001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.aci; 021 022 023import java.util.ArrayList; 024import java.util.Collection; 025import java.util.Collections; 026 027 028/** 029 * Represents permissions to be applied to all {@link ProtectedItem}s in 030 * {@link ItemFirstACIItem}. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class ItemPermission extends Permission 035{ 036 /** The user classes. */ 037 private final Collection<UserClass> userClasses; 038 039 040 /** 041 * Creates a new instance 042 * 043 * @param precedence the precedence of this permission (<tt>-1</tt> to use the 044 * default) 045 * @param grantsAndDenials the collection of {@link GrantAndDenial}s 046 * @param userClasses the collection of {@link UserClass}es 047 */ 048 public ItemPermission( Integer precedence, Collection<GrantAndDenial> grantsAndDenials, 049 Collection<UserClass> userClasses ) 050 { 051 super( precedence, grantsAndDenials ); 052 053 this.userClasses = Collections.unmodifiableCollection( new ArrayList<UserClass>( userClasses ) ); 054 } 055 056 057 /** 058 * Gets the collection of {@link UserClass}es. 059 * 060 * @return the collection of {@link UserClass}es 061 */ 062 public Collection<UserClass> getUserClasses() 063 { 064 return userClasses; 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 @Override 072 public String toString() 073 { 074 StringBuilder buffer = new StringBuilder(); 075 076 buffer.append( "{ " ); 077 078 if ( getPrecedence() != null ) 079 { 080 buffer.append( "precedence " ); 081 buffer.append( getPrecedence() ); 082 buffer.append( ", " ); 083 } 084 085 buffer.append( "userClasses { " ); 086 087 boolean isFirst = true; 088 089 for ( UserClass userClass : userClasses ) 090 { 091 if ( isFirst ) 092 { 093 isFirst = false; 094 } 095 else 096 { 097 buffer.append( ", " ); 098 } 099 100 buffer.append( userClass.toString() ); 101 } 102 103 buffer.append( " }, grantsAndDenials { " ); 104 105 isFirst = true; 106 107 for ( GrantAndDenial grantAndDenial : getGrantsAndDenials() ) 108 { 109 if ( isFirst ) 110 { 111 isFirst = false; 112 } 113 else 114 { 115 buffer.append( ", " ); 116 } 117 118 buffer.append( grantAndDenial.toString() ); 119 } 120 121 buffer.append( " } }" ); 122 123 return buffer.toString(); 124 } 125}