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 * http://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.protectedItem; 21 22 23 import java.util.Collections; 24 import java.util.Iterator; 25 import java.util.Set; 26 27 import org.apache.directory.api.ldap.aci.ProtectedItem; 28 29 30 /** 31 * Restricts values added to the attribute type to being values that are 32 * already present in the same entry as values of the attribute valuesIn. It 33 * is examined if the protected item is an attribute value of the specified 34 * type and the permission sought is add. Values of the valuesIn attribute 35 * are checked without regard to context or access control and as though the 36 * operation which adds the values were successful. If the value to be added 37 * is not present in valuesIn the ACI item is treated as not granting add 38 * access. 39 */ 40 public class RestrictedByItem extends ProtectedItem 41 { 42 /** The set of restricted elements */ 43 private final Set<RestrictedByElem> items; 44 45 46 /** 47 * Creates a new instance. 48 * 49 * @param items the collection of {@link RestrictedByElem}s. 50 */ 51 public RestrictedByItem( Set<RestrictedByElem> items ) 52 { 53 this.items = Collections.unmodifiableSet( items ); 54 } 55 56 57 /** 58 * Gets an iterator of all {@link RestrictedByElem}s. 59 * 60 * @return the iterator of all {@link RestrictedByElem}s 61 */ 62 public Iterator<RestrictedByElem> iterator() 63 { 64 return items.iterator(); 65 } 66 67 68 /** 69 * {@inheritDoc} 70 */ 71 @Override 72 public int hashCode() 73 { 74 int hash = 37; 75 hash = hash * 17 + items.hashCode(); 76 return hash; 77 } 78 79 80 /** 81 * {@inheritDoc} 82 */ 83 @Override 84 public boolean equals( Object o ) 85 { 86 if ( this == o ) 87 { 88 return true; 89 } 90 91 if ( o == null ) 92 { 93 return false; 94 } 95 96 if ( o instanceof RestrictedByItem ) 97 { 98 RestrictedByItem that = ( RestrictedByItem ) o; 99 return this.items.equals( that.items ); 100 } 101 102 return false; 103 } 104 105 106 /** 107 * {@inheritDoc} 108 */ 109 @Override 110 public String toString() 111 { 112 StringBuilder buf = new StringBuilder(); 113 114 buf.append( "restrictedBy {" ); 115 116 boolean isFirst = true; 117 118 for ( RestrictedByElem item : items ) 119 { 120 if ( isFirst ) 121 { 122 isFirst = false; 123 } 124 else 125 { 126 buf.append( ", " ); 127 } 128 129 buf.append( item.toString() ); 130 } 131 132 buf.append( '}' ); 133 134 return buf.toString(); 135 } 136 }