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 */ 020 package org.apache.directory.shared.ldap.aci; 021 022 023 import java.io.Serializable; 024 import java.util.Collection; 025 import java.util.HashSet; 026 import java.util.Set; 027 028 import org.apache.directory.shared.i18n.I18n; 029 import org.apache.directory.shared.ldap.constants.AuthenticationLevel; 030 031 032 /** 033 * An abstract class that provides common properties and operations for 034 * {@link ItemFirstACIItem} and {@link UserFirstACIItem} as specified X.501 035 * specification. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 * @version $Rev: 912399 $, $Date: 2010-02-21 21:52:31 +0100 (Sun, 21 Feb 2010) $ 039 */ 040 public abstract class ACIItem implements Serializable 041 { 042 private String identificationTag; 043 044 /* 0 ~ 255 */ 045 private int precedence = 0; 046 047 private AuthenticationLevel authenticationLevel; 048 049 050 /** 051 * Creates a new instance 052 * 053 * @param identificationTag 054 * the id string of this item 055 * @param precedence 056 * the precedence of this item 057 * @param authenticationLevel 058 * the level of authentication required to this item 059 */ 060 protected ACIItem(String identificationTag, int precedence, AuthenticationLevel authenticationLevel) 061 { 062 if ( identificationTag == null ) 063 { 064 throw new NullPointerException( I18n.err( I18n.ERR_04001 ) ); 065 } 066 if ( precedence < 0 || precedence > 255 ) 067 { 068 throw new IllegalArgumentException( I18n.err( I18n.ERR_04002, precedence ) ); 069 } 070 if ( authenticationLevel == null ) 071 { 072 throw new NullPointerException( I18n.err( I18n.ERR_04003 ) ); 073 } 074 075 this.identificationTag = identificationTag; 076 this.precedence = precedence; 077 this.authenticationLevel = authenticationLevel; 078 } 079 080 081 /** 082 * Returns the id string of this item. 083 */ 084 public String getIdentificationTag() 085 { 086 return identificationTag; 087 } 088 089 090 /** 091 * Returns the precedence of this item. 092 */ 093 public int getPrecedence() 094 { 095 return precedence; 096 } 097 098 099 /** 100 * Returns the level of authentication required to this item. 101 */ 102 public AuthenticationLevel getAuthenticationLevel() 103 { 104 return authenticationLevel; 105 } 106 107 108 /** 109 * Converts this item into a collection of {@link ACITuple}s and returns 110 * it. 111 */ 112 public abstract Collection<ACITuple> toTuples(); 113 114 115 /** 116 * Converts a set of {@link GrantAndDenial}s into a set of 117 * {@link MicroOperation}s and returns it. 118 */ 119 protected static Set<MicroOperation> toMicroOperations( Set<GrantAndDenial> grantsAndDenials ) 120 { 121 Set<MicroOperation> microOps = new HashSet<MicroOperation>(); 122 123 for ( GrantAndDenial grantAndDenial:grantsAndDenials ) 124 { 125 microOps.add( grantAndDenial.getMicroOperation() ); 126 } 127 128 return microOps; 129 } 130 }