Add bean wrappers
[ccsdk/apps.git] / ms / sliboot / src / main / java / org / onap / ccsdk / apps / ms / sliboot / App.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - CCSDK\r
4  * ================================================================================\r
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.onap.ccsdk.apps.ms.sliboot;\r
22 \r
23 import org.slf4j.Logger;\r
24 import org.slf4j.LoggerFactory;\r
25 import org.springframework.boot.SpringApplication;\r
26 import org.springframework.boot.autoconfigure.SpringBootApplication;\r
27 import org.springframework.context.annotation.ComponentScan;\r
28 import springfox.documentation.swagger2.annotations.EnableSwagger2;\r
29 import org.apache.shiro.realm.Realm;\r
30 import org.apache.shiro.realm.text.PropertiesRealm;\r
31 import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;\r
32 import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;\r
33 import org.springframework.context.annotation.Bean;\r
34 import org.onap.aaf.cadi.shiro.AAFRealm;\r
35 \r
36 @SpringBootApplication\r
37 @EnableSwagger2\r
38 @ComponentScan(basePackages = { "org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services" })\r
39 public class App {\r
40 \r
41   private static final Logger log = LoggerFactory.getLogger(App.class);\r
42 \r
43   public static void main(String[] args) throws Exception {\r
44     SpringApplication.run(App.class, args);\r
45   }\r
46 \r
47   @Bean\r
48   public Realm realm() {\r
49 \r
50     // If cadi prop files is not defined use local properties realm\r
51     // src/main/resources/shiro-users.properties\r
52     if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {\r
53       log.info("cadi_prop_files undefined, AAF Realm will not be set");\r
54       PropertiesRealm realm = new PropertiesRealm();\r
55       return realm;\r
56     } else {\r
57       AAFRealm realm = new AAFRealm();\r
58       return realm;\r
59     }\r
60 \r
61   }\r
62 \r
63   @Bean\r
64   public ShiroFilterChainDefinition shiroFilterChainDefinition() {\r
65     DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();\r
66 \r
67     // if cadi prop files is not set disable authentication\r
68     if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {\r
69       chainDefinition.addPathDefinition("/**", "anon");\r
70     } else {\r
71       log.info("Loaded property cadi_prop_files, AAF REALM set");\r
72       chainDefinition.addPathDefinition("/**", "authcBasic, rest[org.onap.sdnc.odl:odl-api]");\r
73     }\r
74 \r
75     return chainDefinition;\r
76   }\r
77 \r
78 }\r