| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>AbstractShiroConfiguration.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: Test Coverage</a> > <a href="../index.html" class="el_bundle">shiro-spring</a> > <a href="index.source.html" class="el_package">org.apache.shiro.spring.config</a> > <span class="el_source">AbstractShiroConfiguration.java</span></div><h1>AbstractShiroConfiguration.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.spring.config; |
| |
| import org.apache.shiro.authc.Authenticator; |
| import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy; |
| import org.apache.shiro.authc.pam.AuthenticationStrategy; |
| import org.apache.shiro.authc.pam.ModularRealmAuthenticator; |
| import org.apache.shiro.authz.Authorizer; |
| import org.apache.shiro.authz.ModularRealmAuthorizer; |
| import org.apache.shiro.authz.permission.PermissionResolver; |
| import org.apache.shiro.authz.permission.RolePermissionResolver; |
| import org.apache.shiro.cache.CacheManager; |
| import org.apache.shiro.config.Ini; |
| import org.apache.shiro.event.EventBus; |
| import org.apache.shiro.mgt.*; |
| import org.apache.shiro.realm.Realm; |
| import org.apache.shiro.realm.text.IniRealm; |
| import org.apache.shiro.session.mgt.DefaultSessionManager; |
| import org.apache.shiro.session.mgt.SessionFactory; |
| import org.apache.shiro.session.mgt.SessionManager; |
| import org.apache.shiro.session.mgt.SimpleSessionFactory; |
| import org.apache.shiro.session.mgt.eis.MemorySessionDAO; |
| import org.apache.shiro.session.mgt.eis.SessionDAO; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.beans.factory.annotation.Value; |
| |
| import java.util.List; |
| |
| /** |
| * @since 1.4.0 |
| */ |
| <span class="fc" id="L49">public class AbstractShiroConfiguration {</span> |
| |
| @Autowired(required = false) |
| protected CacheManager cacheManager; |
| |
| @Autowired(required = false) |
| protected RolePermissionResolver rolePermissionResolver; |
| |
| @Autowired(required = false) |
| protected PermissionResolver permissionResolver; |
| |
| @Autowired |
| protected EventBus eventBus; |
| |
| @Value("#{ @environment['shiro.sessionManager.deleteInvalidSessions'] ?: true }") |
| protected boolean sessionManagerDeleteInvalidSessions; |
| |
| |
| protected SessionsSecurityManager securityManager(List<Realm> realms) { |
| <span class="fc" id="L68"> SessionsSecurityManager securityManager = createSecurityManager();</span> |
| <span class="fc" id="L69"> securityManager.setAuthenticator(authenticator());</span> |
| <span class="fc" id="L70"> securityManager.setAuthorizer(authorizer());</span> |
| <span class="fc" id="L71"> securityManager.setRealms(realms);</span> |
| <span class="fc" id="L72"> securityManager.setSessionManager(sessionManager());</span> |
| <span class="fc" id="L73"> securityManager.setEventBus(eventBus);</span> |
| |
| <span class="fc bfc" id="L75" title="All 2 branches covered."> if (cacheManager != null) {</span> |
| <span class="fc" id="L76"> securityManager.setCacheManager(cacheManager);</span> |
| } |
| |
| <span class="fc" id="L79"> return securityManager;</span> |
| } |
| |
| protected SessionManager sessionManager() { |
| <span class="fc" id="L83"> DefaultSessionManager sessionManager = new DefaultSessionManager();</span> |
| <span class="fc" id="L84"> sessionManager.setSessionDAO(sessionDAO());</span> |
| <span class="fc" id="L85"> sessionManager.setSessionFactory(sessionFactory());</span> |
| <span class="fc" id="L86"> sessionManager.setDeleteInvalidSessions(sessionManagerDeleteInvalidSessions);</span> |
| <span class="fc" id="L87"> return sessionManager;</span> |
| } |
| |
| |
| protected SessionsSecurityManager createSecurityManager() { |
| <span class="fc" id="L92"> DefaultSecurityManager securityManager = new DefaultSecurityManager();</span> |
| <span class="fc" id="L93"> securityManager.setSubjectDAO(subjectDAO());</span> |
| <span class="fc" id="L94"> securityManager.setSubjectFactory(subjectFactory());</span> |
| |
| <span class="fc" id="L96"> RememberMeManager rememberMeManager = rememberMeManager();</span> |
| <span class="pc bpc" id="L97" title="1 of 2 branches missed."> if (rememberMeManager != null) {</span> |
| <span class="nc" id="L98"> securityManager.setRememberMeManager(rememberMeManager);</span> |
| } |
| |
| <span class="fc" id="L101"> return securityManager;</span> |
| } |
| |
| protected RememberMeManager rememberMeManager() { |
| <span class="fc" id="L105"> return null;</span> |
| } |
| |
| protected SubjectDAO subjectDAO() { |
| <span class="fc" id="L109"> DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();</span> |
| <span class="fc" id="L110"> subjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator());</span> |
| <span class="fc" id="L111"> return subjectDAO;</span> |
| } |
| |
| protected SessionStorageEvaluator sessionStorageEvaluator() { |
| <span class="fc" id="L115"> return new DefaultSessionStorageEvaluator();</span> |
| } |
| |
| protected SubjectFactory subjectFactory() { |
| <span class="fc" id="L119"> return new DefaultSubjectFactory();</span> |
| } |
| |
| |
| protected SessionFactory sessionFactory() { |
| <span class="fc" id="L124"> return new SimpleSessionFactory();</span> |
| } |
| |
| protected SessionDAO sessionDAO() { |
| <span class="fc" id="L128"> return new MemorySessionDAO();</span> |
| } |
| |
| protected Authorizer authorizer() { |
| <span class="fc" id="L132"> ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();</span> |
| |
| <span class="fc bfc" id="L134" title="All 2 branches covered."> if (permissionResolver != null) {</span> |
| <span class="fc" id="L135"> authorizer.setPermissionResolver(permissionResolver);</span> |
| } |
| |
| <span class="fc bfc" id="L138" title="All 2 branches covered."> if (rolePermissionResolver != null) {</span> |
| <span class="fc" id="L139"> authorizer.setRolePermissionResolver(rolePermissionResolver);</span> |
| } |
| |
| <span class="fc" id="L142"> return authorizer;</span> |
| } |
| |
| protected AuthenticationStrategy authenticationStrategy() { |
| <span class="fc" id="L146"> return new AtLeastOneSuccessfulStrategy();</span> |
| } |
| |
| protected Authenticator authenticator() { |
| <span class="fc" id="L150"> ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();</span> |
| <span class="fc" id="L151"> authenticator.setAuthenticationStrategy(authenticationStrategy());</span> |
| <span class="fc" id="L152"> return authenticator;</span> |
| } |
| |
| protected Realm iniRealmFromLocation(String iniLocation) { |
| <span class="nc" id="L156"> Ini ini = Ini.fromResourcePath(iniLocation);</span> |
| <span class="nc" id="L157"> return new IniRealm( ini );</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html> |