| <?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>SimpleAuthorizationInfo.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 :: Core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.authz</a> > <span class="el_source">SimpleAuthorizationInfo.java</span></div><h1>SimpleAuthorizationInfo.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.authz; |
| |
| import java.util.Collection; |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| /** |
| * Simple POJO implementation of the {@link AuthorizationInfo} interface that stores roles and permissions as internal |
| * attributes. |
| * |
| * @see org.apache.shiro.realm.AuthorizingRealm |
| * @since 0.9 |
| */ |
| public class SimpleAuthorizationInfo implements AuthorizationInfo { |
| |
| /** |
| * The internal roles collection. |
| */ |
| protected Set<String> roles; |
| |
| /** |
| * Collection of all string-based permissions associated with the account. |
| */ |
| protected Set<String> stringPermissions; |
| |
| /** |
| * Collection of all object-based permissions associaed with the account. |
| */ |
| protected Set<Permission> objectPermissions; |
| |
| /** |
| * Default no-argument constructor. |
| */ |
| <span class="fc" id="L52"> public SimpleAuthorizationInfo() {</span> |
| <span class="fc" id="L53"> }</span> |
| |
| /** |
| * Creates a new instance with the specified roles and no permissions. |
| * @param roles the roles assigned to the realm account. |
| */ |
| <span class="fc" id="L59"> public SimpleAuthorizationInfo(Set<String> roles) {</span> |
| <span class="fc" id="L60"> this.roles = roles;</span> |
| <span class="fc" id="L61"> }</span> |
| |
| public Set<String> getRoles() { |
| <span class="fc" id="L64"> return roles;</span> |
| } |
| |
| /** |
| * Sets the roles assigned to the account. |
| * @param roles the roles assigned to the account. |
| */ |
| public void setRoles(Set<String> roles) { |
| <span class="fc" id="L72"> this.roles = roles;</span> |
| <span class="fc" id="L73"> }</span> |
| |
| /** |
| * Adds (assigns) a role to those associated with the account. If the account doesn't yet have any roles, a |
| * new roles collection (a Set) will be created automatically. |
| * @param role the role to add to those associated with the account. |
| */ |
| public void addRole(String role) { |
| <span class="fc bfc" id="L81" title="All 2 branches covered."> if (this.roles == null) {</span> |
| <span class="fc" id="L82"> this.roles = new HashSet<String>();</span> |
| } |
| <span class="fc" id="L84"> this.roles.add(role);</span> |
| <span class="fc" id="L85"> }</span> |
| |
| /** |
| * Adds (assigns) multiple roles to those associated with the account. If the account doesn't yet have any roles, a |
| * new roles collection (a Set) will be created automatically. |
| * @param roles the roles to add to those associated with the account. |
| */ |
| public void addRoles(Collection<String> roles) { |
| <span class="nc bnc" id="L93" title="All 2 branches missed."> if (this.roles == null) {</span> |
| <span class="nc" id="L94"> this.roles = new HashSet<String>();</span> |
| } |
| <span class="nc" id="L96"> this.roles.addAll(roles);</span> |
| <span class="nc" id="L97"> }</span> |
| |
| public Set<String> getStringPermissions() { |
| <span class="fc" id="L100"> return stringPermissions;</span> |
| } |
| |
| /** |
| * Sets the string-based permissions assigned directly to the account. The permissions set here, in addition to any |
| * {@link #getObjectPermissions() object permissions} constitute the total permissions assigned directly to the |
| * account. |
| * |
| * @param stringPermissions the string-based permissions assigned directly to the account. |
| */ |
| public void setStringPermissions(Set<String> stringPermissions) { |
| <span class="fc" id="L111"> this.stringPermissions = stringPermissions;</span> |
| <span class="fc" id="L112"> }</span> |
| |
| /** |
| * Adds (assigns) a permission to those directly associated with the account. If the account doesn't yet have any |
| * direct permissions, a new permission collection (a Set&lt;String&gt;) will be created automatically. |
| * @param permission the permission to add to those directly assigned to the account. |
| */ |
| public void addStringPermission(String permission) { |
| <span class="nc bnc" id="L120" title="All 2 branches missed."> if (this.stringPermissions == null) {</span> |
| <span class="nc" id="L121"> this.stringPermissions = new HashSet<String>();</span> |
| } |
| <span class="nc" id="L123"> this.stringPermissions.add(permission);</span> |
| <span class="nc" id="L124"> }</span> |
| |
| /** |
| * Adds (assigns) multiple permissions to those associated directly with the account. If the account doesn't yet |
| * have any string-based permissions, a new permissions collection (a Set&lt;String&gt;) will be created automatically. |
| * @param permissions the permissions to add to those associated directly with the account. |
| */ |
| public void addStringPermissions(Collection<String> permissions) { |
| <span class="nc bnc" id="L132" title="All 2 branches missed."> if (this.stringPermissions == null) {</span> |
| <span class="nc" id="L133"> this.stringPermissions = new HashSet<String>();</span> |
| } |
| <span class="nc" id="L135"> this.stringPermissions.addAll(permissions);</span> |
| <span class="nc" id="L136"> }</span> |
| |
| public Set<Permission> getObjectPermissions() { |
| <span class="fc" id="L139"> return objectPermissions;</span> |
| } |
| |
| /** |
| * Sets the object-based permissions assigned directly to the account. The permissions set here, in addition to any |
| * {@link #getStringPermissions() string permissions} constitute the total permissions assigned directly to the |
| * account. |
| * |
| * @param objectPermissions the object-based permissions assigned directly to the account. |
| */ |
| public void setObjectPermissions(Set<Permission> objectPermissions) { |
| <span class="nc" id="L150"> this.objectPermissions = objectPermissions;</span> |
| <span class="nc" id="L151"> }</span> |
| |
| /** |
| * Adds (assigns) a permission to those directly associated with the account. If the account doesn't yet have any |
| * direct permissions, a new permission collection (a Set&lt;{@link Permission Permission}&gt;) will be created automatically. |
| * @param permission the permission to add to those directly assigned to the account. |
| */ |
| public void addObjectPermission(Permission permission) { |
| <span class="nc bnc" id="L159" title="All 2 branches missed."> if (this.objectPermissions == null) {</span> |
| <span class="nc" id="L160"> this.objectPermissions = new HashSet<Permission>();</span> |
| } |
| <span class="nc" id="L162"> this.objectPermissions.add(permission);</span> |
| <span class="nc" id="L163"> }</span> |
| |
| /** |
| * Adds (assigns) multiple permissions to those associated directly with the account. If the account doesn't yet |
| * have any object-based permissions, a new permissions collection (a Set&lt;{@link Permission Permission}&gt;) |
| * will be created automatically. |
| * @param permissions the permissions to add to those associated directly with the account. |
| */ |
| public void addObjectPermissions(Collection<Permission> permissions) { |
| <span class="fc bfc" id="L172" title="All 2 branches covered."> if (this.objectPermissions == null) {</span> |
| <span class="fc" id="L173"> this.objectPermissions = new HashSet<Permission>();</span> |
| } |
| <span class="fc" id="L175"> this.objectPermissions.addAll(permissions);</span> |
| <span class="fc" id="L176"> }</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> |