| <?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>AuthorizingSecurityManager.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 :: Jar Bundle</a> > <a href="../index.html" class="el_bundle">shiro-core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.mgt</a> > <span class="el_source">AuthorizingSecurityManager.java</span></div><h1>AuthorizingSecurityManager.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.mgt; |
| |
| import org.apache.shiro.authz.AuthorizationException; |
| import org.apache.shiro.authz.Authorizer; |
| import org.apache.shiro.authz.ModularRealmAuthorizer; |
| import org.apache.shiro.authz.Permission; |
| import org.apache.shiro.subject.PrincipalCollection; |
| import org.apache.shiro.util.LifecycleUtils; |
| |
| import java.util.Collection; |
| import java.util.List; |
| |
| |
| /** |
| * Shiro support of a {@link SecurityManager} class hierarchy that delegates all |
| * authorization (access control) operations to a wrapped {@link Authorizer Authorizer} instance. That is, |
| * this class implements all the <tt>Authorizer</tt> methods in the {@link SecurityManager SecurityManager} |
| * interface, but in reality, those methods are merely passthrough calls to the underlying 'real' |
| * <tt>Authorizer</tt> instance. |
| * |
| * <p>All remaining <tt>SecurityManager</tt> methods not covered by this class or its parents (mostly Session support) |
| * are left to be implemented by subclasses. |
| * |
| * <p>In keeping with the other classes in this hierarchy and Shiro's desire to minimize configuration whenever |
| * possible, suitable default instances for all dependencies will be created upon instantiation. |
| * |
| * @since 0.9 |
| */ |
| public abstract class AuthorizingSecurityManager extends AuthenticatingSecurityManager { |
| |
| /** |
| * The wrapped instance to which all of this <tt>SecurityManager</tt> authorization calls are delegated. |
| */ |
| private Authorizer authorizer; |
| |
| /** |
| * Default no-arg constructor that initializes an internal default |
| * {@link org.apache.shiro.authz.ModularRealmAuthorizer ModularRealmAuthorizer}. |
| */ |
| public AuthorizingSecurityManager() { |
| <span class="fc" id="L59"> super();</span> |
| <span class="fc" id="L60"> this.authorizer = new ModularRealmAuthorizer();</span> |
| <span class="fc" id="L61"> }</span> |
| |
| /** |
| * Returns the underlying wrapped <tt>Authorizer</tt> instance to which this <tt>SecurityManager</tt> |
| * implementation delegates all of its authorization calls. |
| * |
| * @return the wrapped <tt>Authorizer</tt> used by this <tt>SecurityManager</tt> implementation. |
| */ |
| public Authorizer getAuthorizer() { |
| <span class="fc" id="L70"> return authorizer;</span> |
| } |
| |
| /** |
| * Sets the underlying <tt>Authorizer</tt> instance to which this <tt>SecurityManager</tt> implementation will |
| * delegate all of its authorization calls. |
| * |
| * @param authorizer the <tt>Authorizer</tt> this <tt>SecurityManager</tt> should wrap and delegate all of its |
| * authorization calls to. |
| */ |
| public void setAuthorizer(Authorizer authorizer) { |
| <span class="nc bnc" id="L81" title="All 2 branches missed."> if (authorizer == null) {</span> |
| <span class="nc" id="L82"> String msg = "Authorizer argument cannot be null.";</span> |
| <span class="nc" id="L83"> throw new IllegalArgumentException(msg);</span> |
| } |
| <span class="nc" id="L85"> this.authorizer = authorizer;</span> |
| <span class="nc" id="L86"> }</span> |
| |
| /** |
| * First calls <code>super.afterRealmsSet()</code> and then sets these same <code>Realm</code> objects on this |
| * instance's wrapped {@link Authorizer Authorizer}. |
| * <p/> |
| * The setting of realms the Authorizer will only occur if it is an instance of |
| * {@link org.apache.shiro.authz.ModularRealmAuthorizer ModularRealmAuthorizer}, that is: |
| * <pre> |
| * if ( this.authorizer instanceof ModularRealmAuthorizer ) { |
| * ((ModularRealmAuthorizer)this.authorizer).setRealms(realms); |
| * }</pre> |
| */ |
| protected void afterRealmsSet() { |
| <span class="fc" id="L100"> super.afterRealmsSet();</span> |
| <span class="pc bpc" id="L101" title="1 of 2 branches missed."> if (this.authorizer instanceof ModularRealmAuthorizer) {</span> |
| <span class="fc" id="L102"> ((ModularRealmAuthorizer) this.authorizer).setRealms(getRealms());</span> |
| } |
| <span class="fc" id="L104"> }</span> |
| |
| public void destroy() { |
| <span class="fc" id="L107"> LifecycleUtils.destroy(getAuthorizer());</span> |
| <span class="fc" id="L108"> this.authorizer = null;</span> |
| <span class="fc" id="L109"> super.destroy();</span> |
| <span class="fc" id="L110"> }</span> |
| |
| public boolean isPermitted(PrincipalCollection principals, String permissionString) { |
| <span class="fc" id="L113"> return this.authorizer.isPermitted(principals, permissionString);</span> |
| } |
| |
| public boolean isPermitted(PrincipalCollection principals, Permission permission) { |
| <span class="nc" id="L117"> return this.authorizer.isPermitted(principals, permission);</span> |
| } |
| |
| public boolean[] isPermitted(PrincipalCollection principals, String... permissions) { |
| <span class="nc" id="L121"> return this.authorizer.isPermitted(principals, permissions);</span> |
| } |
| |
| public boolean[] isPermitted(PrincipalCollection principals, List<Permission> permissions) { |
| <span class="nc" id="L125"> return this.authorizer.isPermitted(principals, permissions);</span> |
| } |
| |
| public boolean isPermittedAll(PrincipalCollection principals, String... permissions) { |
| <span class="nc" id="L129"> return this.authorizer.isPermittedAll(principals, permissions);</span> |
| } |
| |
| public boolean isPermittedAll(PrincipalCollection principals, Collection<Permission> permissions) { |
| <span class="nc" id="L133"> return this.authorizer.isPermittedAll(principals, permissions);</span> |
| } |
| |
| public void checkPermission(PrincipalCollection principals, String permission) throws AuthorizationException { |
| <span class="nc" id="L137"> this.authorizer.checkPermission(principals, permission);</span> |
| <span class="nc" id="L138"> }</span> |
| |
| public void checkPermission(PrincipalCollection principals, Permission permission) throws AuthorizationException { |
| <span class="nc" id="L141"> this.authorizer.checkPermission(principals, permission);</span> |
| <span class="nc" id="L142"> }</span> |
| |
| public void checkPermissions(PrincipalCollection principals, String... permissions) throws AuthorizationException { |
| <span class="nc" id="L145"> this.authorizer.checkPermissions(principals, permissions);</span> |
| <span class="nc" id="L146"> }</span> |
| |
| public void checkPermissions(PrincipalCollection principals, Collection<Permission> permissions) throws AuthorizationException { |
| <span class="nc" id="L149"> this.authorizer.checkPermissions(principals, permissions);</span> |
| <span class="nc" id="L150"> }</span> |
| |
| public boolean hasRole(PrincipalCollection principals, String roleIdentifier) { |
| <span class="fc" id="L153"> return this.authorizer.hasRole(principals, roleIdentifier);</span> |
| } |
| |
| public boolean[] hasRoles(PrincipalCollection principals, List<String> roleIdentifiers) { |
| <span class="nc" id="L157"> return this.authorizer.hasRoles(principals, roleIdentifiers);</span> |
| } |
| |
| public boolean hasAllRoles(PrincipalCollection principals, Collection<String> roleIdentifiers) { |
| <span class="nc" id="L161"> return this.authorizer.hasAllRoles(principals, roleIdentifiers);</span> |
| } |
| |
| public void checkRole(PrincipalCollection principals, String role) throws AuthorizationException { |
| <span class="nc" id="L165"> this.authorizer.checkRole(principals, role);</span> |
| <span class="nc" id="L166"> }</span> |
| |
| public void checkRoles(PrincipalCollection principals, Collection<String> roles) throws AuthorizationException { |
| <span class="nc" id="L169"> this.authorizer.checkRoles(principals, roles);</span> |
| <span class="nc" id="L170"> }</span> |
| |
| public void checkRoles(PrincipalCollection principals, String... roles) throws AuthorizationException { |
| <span class="nc" id="L173"> this.authorizer.checkRoles(principals, roles);</span> |
| <span class="nc" id="L174"> } </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> |