001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.spring.boot.autoconfigure;
020
021import org.apache.shiro.authc.Authenticator;
022import org.apache.shiro.authc.pam.AuthenticationStrategy;
023import org.apache.shiro.authz.Authorizer;
024import org.apache.shiro.mgt.SessionStorageEvaluator;
025import org.apache.shiro.mgt.SessionsSecurityManager;
026import org.apache.shiro.mgt.SubjectDAO;
027import org.apache.shiro.mgt.SubjectFactory;
028import org.apache.shiro.realm.Realm;
029import org.apache.shiro.session.mgt.SessionFactory;
030import org.apache.shiro.session.mgt.SessionManager;
031import org.apache.shiro.session.mgt.eis.SessionDAO;
032import org.apache.shiro.spring.boot.autoconfigure.exception.NoRealmBeanConfiguredException;
033import org.apache.shiro.spring.config.AbstractShiroConfiguration;
034import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
035import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
036import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
037import org.springframework.context.annotation.Bean;
038import org.springframework.context.annotation.Configuration;
039
040import java.util.List;
041
042/**
043 * @since 1.4.0
044 */
045@Configuration
046@SuppressWarnings("SpringFacetCodeInspection")
047@ConditionalOnProperty(name = "shiro.enabled", matchIfMissing = true)
048public class ShiroAutoConfiguration extends AbstractShiroConfiguration {
049
050    @Bean
051    @ConditionalOnMissingBean
052    @Override
053    protected AuthenticationStrategy authenticationStrategy() {
054        return super.authenticationStrategy();
055    }
056
057    @Bean
058    @ConditionalOnMissingBean
059    @Override
060    protected Authenticator authenticator() {
061        return super.authenticator();
062    }
063
064    @Bean
065    @ConditionalOnMissingBean
066    @Override
067    protected Authorizer authorizer() {
068        return super.authorizer();
069    }
070
071    @Bean
072    @ConditionalOnMissingBean
073    @Override
074    protected SubjectDAO subjectDAO() {
075        return super.subjectDAO();
076    }
077
078    @Bean
079    @ConditionalOnMissingBean
080    @Override
081    protected SessionStorageEvaluator sessionStorageEvaluator() {
082        return super.sessionStorageEvaluator();
083    }
084
085    @Bean
086    @ConditionalOnMissingBean
087    @Override
088    protected SubjectFactory subjectFactory() {
089        return super.subjectFactory();
090    }
091
092    @Bean
093    @ConditionalOnMissingBean
094    @Override
095    protected SessionFactory sessionFactory() {
096        return super.sessionFactory();
097    }
098
099    @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}