| <?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 :: All (aggregate jar)</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.event.EventBus; |
| import org.apache.shiro.mgt.*; |
| import org.apache.shiro.realm.Realm; |
| 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="L47">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="L66"> SessionsSecurityManager securityManager = createSecurityManager();</span> |
| <span class="fc" id="L67"> securityManager.setAuthenticator(authenticator());</span> |
| <span class="fc" id="L68"> securityManager.setAuthorizer(authorizer());</span> |
| <span class="fc" id="L69"> securityManager.setRealms(realms);</span> |
| <span class="fc" id="L70"> securityManager.setSessionManager(sessionManager());</span> |
| <span class="fc" id="L71"> securityManager.setEventBus(eventBus);</span> |
| |
| <span class="fc bfc" id="L73" title="All 2 branches covered."> if (cacheManager != null) {</span> |
| <span class="fc" id="L74"> securityManager.setCacheManager(cacheManager);</span> |
| } |
| |
| <span class="fc" id="L77"> return securityManager;</span> |
| } |
| |
| protected SessionManager sessionManager() { |
| <span class="fc" id="L81"> DefaultSessionManager sessionManager = new DefaultSessionManager();</span> |
| <span class="fc" id="L82"> sessionManager.setSessionDAO(sessionDAO());</span> |
| <span class="fc" id="L83"> sessionManager.setSessionFactory(sessionFactory());</span> |
| <span class="fc" id="L84"> sessionManager.setDeleteInvalidSessions(sessionManagerDeleteInvalidSessions);</span> |
| <span class="fc" id="L85"> return sessionManager;</span> |
| } |
| |
| |
| protected SessionsSecurityManager createSecurityManager() { |
| <span class="fc" id="L90"> DefaultSecurityManager securityManager = new DefaultSecurityManager();</span> |
| <span class="fc" id="L91"> securityManager.setSubjectDAO(subjectDAO());</span> |
| <span class="fc" id="L92"> securityManager.setSubjectFactory(subjectFactory());</span> |
| |
| <span class="fc" id="L94"> RememberMeManager rememberMeManager = rememberMeManager();</span> |
| <span class="pc bpc" id="L95" title="1 of 2 branches missed."> if (rememberMeManager != null) {</span> |
| <span class="nc" id="L96"> securityManager.setRememberMeManager(rememberMeManager);</span> |
| } |
| |
| <span class="fc" id="L99"> return securityManager;</span> |
| } |
| |
| protected RememberMeManager rememberMeManager() { |
| <span class="fc" id="L103"> return null;</span> |
| } |
| |
| protected SubjectDAO subjectDAO() { |
| <span class="fc" id="L107"> DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();</span> |
| <span class="fc" id="L108"> subjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator());</span> |
| <span class="fc" id="L109"> return subjectDAO;</span> |
| } |
| |
| protected SessionStorageEvaluator sessionStorageEvaluator() { |
| <span class="fc" id="L113"> return new DefaultSessionStorageEvaluator();</span> |
| } |
| |
| protected SubjectFactory subjectFactory() { |
| <span class="fc" id="L117"> return new DefaultSubjectFactory();</span> |
| } |
| |
| |
| protected SessionFactory sessionFactory() { |
| <span class="fc" id="L122"> return new SimpleSessionFactory();</span> |
| } |
| |
| protected SessionDAO sessionDAO() { |
| <span class="fc" id="L126"> return new MemorySessionDAO();</span> |
| } |
| |
| protected Authorizer authorizer() { |
| <span class="fc" id="L130"> ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();</span> |
| |
| <span class="fc bfc" id="L132" title="All 2 branches covered."> if (permissionResolver != null) {</span> |
| <span class="fc" id="L133"> authorizer.setPermissionResolver(permissionResolver);</span> |
| } |
| |
| <span class="fc bfc" id="L136" title="All 2 branches covered."> if (rolePermissionResolver != null) {</span> |
| <span class="fc" id="L137"> authorizer.setRolePermissionResolver(rolePermissionResolver);</span> |
| } |
| |
| <span class="fc" id="L140"> return authorizer;</span> |
| } |
| |
| protected AuthenticationStrategy authenticationStrategy() { |
| <span class="fc" id="L144"> return new AtLeastOneSuccessfulStrategy();</span> |
| } |
| |
| protected Authenticator authenticator() { |
| <span class="fc" id="L148"> ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();</span> |
| <span class="fc" id="L149"> authenticator.setAuthenticationStrategy(authenticationStrategy());</span> |
| <span class="fc" id="L150"> return authenticator;</span> |
| } |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html> |