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.Collection; 024import java.util.Collections; 025 026 027/** 028 * Represents permissions to be applied to all {@link UserClass}es in 029 * {@link UserFirstACIItem}. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class UserPermission extends Permission 034{ 035 /** The protected items. */ 036 private final Collection<ProtectedItem> protectedItems; 037 038 039 /** 040 * Creates a new instance 041 * 042 * @param precedence 043 * the precedence of this permission (<tt>-1</tt> to use the 044 * default) 045 * @param grantsAndDenials 046 * the set of {@link GrantAndDenial}s 047 * @param protectedItems 048 * the collection of {@link ProtectedItem}s 049 */ 050 public UserPermission( Integer precedence, Collection<GrantAndDenial> grantsAndDenials, 051 Collection<ProtectedItem> protectedItems ) 052 { 053 super( precedence, grantsAndDenials ); 054 055 this.protectedItems = Collections.unmodifiableCollection( protectedItems ); 056 } 057 058 059 /** 060 * Gets the collection of {@link ProtectedItem}s. 061 * 062 * @return the collection of {@link ProtectedItem}s 063 */ 064 public Collection<ProtectedItem> getProtectedItems() 065 { 066 return protectedItems; 067 } 068 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public String toString() 075 { 076 StringBuilder buf = new StringBuilder(); 077 078 buf.append( "{ " ); 079 080 if ( getPrecedence() != null ) 081 { 082 buf.append( "precedence " ); 083 buf.append( getPrecedence() ); 084 buf.append( ", " ); 085 } 086 087 buf.append( "protectedItems { " ); 088 089 boolean isFirst = true; 090 091 for ( ProtectedItem item : protectedItems ) 092 { 093 if ( isFirst ) 094 { 095 isFirst = false; 096 } 097 else 098 { 099 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}