Refactor sliapi springboot
[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.*" })\r
39 \r
40 public class App {\r
41 \r
42   private static final Logger log = LoggerFactory.getLogger(App.class);\r
43 \r
44   public static void main(String[] args) throws Exception {\r
45     SpringApplication.run(App.class, args);\r
46   }\r
47 \r
48   @Bean\r
49   public Realm realm() {\r
50 \r
51     // If cadi prop files is not defined use local properties realm\r
52     // src/main/resources/shiro-users.properties\r
53     if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {\r
54       log.info("cadi_prop_files undefined, AAF Realm will not be set");\r
55       PropertiesRealm realm = new PropertiesRealm();\r
56       return realm;\r
57     } else {\r
58       AAFRealm realm = new AAFRealm();\r
59       return realm;\r
60     }\r
61 \r
62   }\r
63 \r
64   @Bean\r
65   public ShiroFilterChainDefinition shiroFilterChainDefinition() {\r
66     DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();\r
67 \r
68     // if cadi prop files is not set disable authentication\r
69     if ("none".equals(System.getProperty("cadi_prop_files", "none"))) {\r
70       chainDefinition.addPathDefinition("/**", "anon");\r
71     } else {\r
72       log.info("Loaded property cadi_prop_files, AAF REALM set");\r
73       chainDefinition.addPathDefinition("/**", "authcBasic, rest[org.onap.sdnc.odl:odl-api]");\r
74     }\r
75 \r
76     return chainDefinition;\r
77   }\r
78 \r
79 }\r