View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.aci;
21  
22  
23  import java.util.Collection;
24  import java.util.Collections;
25  
26  
27  /**
28   * Represents permissions to be applied to all {@link UserClass}es in
29   * {@link UserFirstACIItem}.
30   * 
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class UserPermission extends Permission
34  {
35      /** The protected items. */
36      private final Collection<ProtectedItem> protectedItems;
37  
38  
39      /**
40       * Creates a new instance
41       * 
42       * @param precedence
43       *            the precedence of this permission (<tt>-1</tt> to use the
44       *            default)
45       * @param grantsAndDenials
46       *            the set of {@link GrantAndDenial}s
47       * @param protectedItems
48       *            the collection of {@link ProtectedItem}s
49       */
50      public UserPermission( Integer precedence, Collection<GrantAndDenial> grantsAndDenials,
51          Collection<ProtectedItem> protectedItems )
52      {
53          super( precedence, grantsAndDenials );
54  
55          this.protectedItems = Collections.unmodifiableCollection( protectedItems );
56      }
57  
58  
59      /**
60       * Gets the collection of {@link ProtectedItem}s.
61       *
62       * @return the collection of {@link ProtectedItem}s
63       */
64      public Collection<ProtectedItem> getProtectedItems()
65      {
66          return protectedItems;
67      }
68  
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      public String toString()
75      {
76          StringBuilder buf = new StringBuilder();
77  
78          buf.append( "{ " );
79  
80          if ( getPrecedence() != null )
81          {
82              buf.append( "precedence " );
83              buf.append( getPrecedence() );
84              buf.append( ", " );
85          }
86  
87          buf.append( "protectedItems { " );
88  
89          boolean isFirst = true;
90  
91          for ( ProtectedItem item : protectedItems )
92          {
93              if ( isFirst )
94              {
95                  isFirst = false;
96              }
97              else
98              {
99                  buf.append( ", " );
100             }
101 
102             buf.append( item.toString() );
103         }
104 
105         buf.append( " }, grantsAndDenials { " );
106 
107         isFirst = true;
108 
109         for ( GrantAndDenial grantAndDenial : getGrantsAndDenials() )
110         {
111             if ( isFirst )
112             {
113                 isFirst = false;
114             }
115             else
116             {
117                 buf.append( ", " );
118             }
119 
120             buf.append( grantAndDenial.toString() );
121         }
122 
123         buf.append( " } }" );
124 
125         return buf.toString();
126     }
127 }