View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.shiro.spring.boot.autoconfigure;
20  
21  import org.apache.shiro.authc.Authenticator;
22  import org.apache.shiro.authc.pam.AuthenticationStrategy;
23  import org.apache.shiro.authz.Authorizer;
24  import org.apache.shiro.mgt.SessionStorageEvaluator;
25  import org.apache.shiro.mgt.SessionsSecurityManager;
26  import org.apache.shiro.mgt.SubjectDAO;
27  import org.apache.shiro.mgt.SubjectFactory;
28  import org.apache.shiro.realm.Realm;
29  import org.apache.shiro.session.mgt.SessionFactory;
30  import org.apache.shiro.session.mgt.SessionManager;
31  import org.apache.shiro.session.mgt.eis.SessionDAO;
32  import org.apache.shiro.spring.boot.autoconfigure.exception.NoRealmBeanConfiguredException;
33  import org.apache.shiro.spring.config.AbstractShiroConfiguration;
34  import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
35  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
36  import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
37  import org.springframework.context.annotation.Bean;
38  import org.springframework.context.annotation.Configuration;
39  
40  import java.util.List;
41  
42  /**
43   * @since 1.4.0
44   */
45  @Configuration
46  @SuppressWarnings("SpringFacetCodeInspection")
47  @ConditionalOnProperty(name = "shiro.enabled", matchIfMissing = true)
48  public class ShiroAutoConfiguration extends AbstractShiroConfiguration {
49  
50      @Bean
51      @ConditionalOnMissingBean
52      @Override
53      protected AuthenticationStrategy authenticationStrategy() {
54          return super.authenticationStrategy();
55      }
56  
57      @Bean
58      @ConditionalOnMissingBean
59      @Override
60      protected Authenticator authenticator() {
61          return super.authenticator();
62      }
63  
64      @Bean
65      @ConditionalOnMissingBean
66      @Override
67      protected Authorizer authorizer() {
68          return super.authorizer();
69      }
70  
71      @Bean
72      @ConditionalOnMissingBean
73      @Override
74      protected SubjectDAO subjectDAO() {
75          return super.subjectDAO();
76      }
77  
78      @Bean
79      @ConditionalOnMissingBean
80      @Override
81      protected SessionStorageEvaluator sessionStorageEvaluator() {
82          return super.sessionStorageEvaluator();
83      }
84  
85      @Bean
86      @ConditionalOnMissingBean
87      @Override
88      protected SubjectFactory subjectFactory() {
89          return super.subjectFactory();
90      }
91  
92      @Bean
93      @ConditionalOnMissingBean
94      @Override
95      protected SessionFactory sessionFactory() {
96          return super.sessionFactory();
97      }
98  
99      @Bean
100     @ConditionalOnMissingBean
101     @Override
102     protected SessionDAO sessionDAO() {
103         return super.sessionDAO();
104     }
105 
106     @Bean
107     @ConditionalOnMissingBean
108     @Override
109     protected SessionManager sessionManager() {
110         return super.sessionManager();
111     }
112 
113     @Bean
114     @ConditionalOnMissingBean
115     @Override
116     protected SessionsSecurityManager securityManager(List<Realm> realms) {
117         return super.securityManager(realms);
118     }
119 
120     @Bean
121     @ConditionalOnResource(resources = "classpath:shiro.ini")
122     protected Realm iniClasspathRealm() {
123         return iniRealmFromLocation("classpath:shiro.ini");
124     }
125 
126     @Bean
127     @ConditionalOnResource(resources = "classpath:META-INF/shiro.ini")
128     protected Realm iniMetaInfClasspathRealm() {
129         return iniRealmFromLocation("classpath:META-INF/shiro.ini");
130     }
131 
132     @Bean
133     @ConditionalOnMissingBean(Realm.class)
134     protected Realm missingRealm() {
135         throw new NoRealmBeanConfiguredException();
136     }
137 
138 
139 }