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 /**
024 * An enumeration that represents grants or denials of {@link MicroOperation}s.
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 * @version $Rev: 638218 $, $Date: 2008-03-18 06:07:20 +0100 (Mar, 18 mar 2008) $
028 */
029 public class GrantAndDenial
030 {
031 // Permissions that may be used in conjunction with any component of
032 // <tt>ProtectedItem</tt>s.
033 /** Grant for {@link MicroOperation#ADD} */
034 public static final GrantAndDenial GRANT_ADD = new GrantAndDenial( MicroOperation.ADD, 0, true );
035
036 /** Denial for {@link MicroOperation#ADD} */
037 public static final GrantAndDenial DENY_ADD = new GrantAndDenial( MicroOperation.ADD, 1, false );
038
039 /** Grant for {@link MicroOperation#DISCLOSE_ON_ERROR} */
040 public static final GrantAndDenial GRANT_DISCLOSE_ON_ERROR = new GrantAndDenial( MicroOperation.DISCLOSE_ON_ERROR,
041 2, true );
042
043 /** Denial for {@link MicroOperation#DISCLOSE_ON_ERROR} */
044 public static final GrantAndDenial DENY_DISCLOSE_ON_ERROR = new GrantAndDenial( MicroOperation.DISCLOSE_ON_ERROR,
045 3, false );
046
047 /** Grant for {@link MicroOperation#READ} */
048 public static final GrantAndDenial GRANT_READ = new GrantAndDenial( MicroOperation.READ, 4, true );
049
050 /** Denial for {@link MicroOperation#READ} */
051 public static final GrantAndDenial DENY_READ = new GrantAndDenial( MicroOperation.READ, 5, false );
052
053 /** Grant for {@link MicroOperation#REMOVE} */
054 public static final GrantAndDenial GRANT_REMOVE = new GrantAndDenial( MicroOperation.REMOVE, 6, true );
055
056 /** Denial for {@link MicroOperation#REMOVE} */
057 public static final GrantAndDenial DENY_REMOVE = new GrantAndDenial( MicroOperation.REMOVE, 7, false );
058
059 // Permissions that may be used only in conjunction with the entry
060 // component.
061 /** Grant for {@link MicroOperation#BROWSE} */
062 public static final GrantAndDenial GRANT_BROWSE = new GrantAndDenial( MicroOperation.BROWSE, 8, true );
063
064 /** Denial for {@link MicroOperation#BROWSE} */
065 public static final GrantAndDenial DENY_BROWSE = new GrantAndDenial( MicroOperation.BROWSE, 9, false );
066
067 /** Grant for {@link MicroOperation#EXPORT} */
068 public static final GrantAndDenial GRANT_EXPORT = new GrantAndDenial( MicroOperation.EXPORT, 10, true );
069
070 /** Denial for {@link MicroOperation#EXPORT} */
071 public static final GrantAndDenial DENY_EXPORT = new GrantAndDenial( MicroOperation.EXPORT, 11, false );
072
073 /** Grant for {@link MicroOperation#IMPORT} */
074 public static final GrantAndDenial GRANT_IMPORT = new GrantAndDenial( MicroOperation.IMPORT, 12, true );
075
076 /** Denial for {@link MicroOperation#IMPORT} */
077 public static final GrantAndDenial DENY_IMPORT = new GrantAndDenial( MicroOperation.IMPORT, 13, false );
078
079 /** Grant for {@link MicroOperation#MODIFY} */
080 public static final GrantAndDenial GRANT_MODIFY = new GrantAndDenial( MicroOperation.MODIFY, 14, true );
081
082 /** Denial for {@link MicroOperation#MODIFY} */
083 public static final GrantAndDenial DENY_MODIFY = new GrantAndDenial( MicroOperation.MODIFY, 15, false );
084
085 /** Grant for {@link MicroOperation#RENAME} */
086 public static final GrantAndDenial GRANT_RENAME = new GrantAndDenial( MicroOperation.RENAME, 16, true );
087
088 /** Denial for {@link MicroOperation#RENAME} */
089 public static final GrantAndDenial DENY_RENAME = new GrantAndDenial( MicroOperation.RENAME, 17, false );
090
091 /** Grant for {@link MicroOperation#RETURN_DN} */
092 public static final GrantAndDenial GRANT_RETURN_DN = new GrantAndDenial( MicroOperation.RETURN_DN, 18, true );
093
094 /** Denial for {@link MicroOperation#RETURN_DN} */
095 public static final GrantAndDenial DENY_RETURN_DN = new GrantAndDenial( MicroOperation.RETURN_DN, 19, false );
096
097 // Permissions that may be used in conjunction with any component,
098 // except entry, of <tt>ProtectedItem</tt>s.
099 /** Grant for {@link MicroOperation#COMPARE} */
100 public static final GrantAndDenial GRANT_COMPARE = new GrantAndDenial( MicroOperation.COMPARE, 20, true );
101
102 /** Deny for {@link MicroOperation#COMPARE} */
103 public static final GrantAndDenial DENY_COMPARE = new GrantAndDenial( MicroOperation.COMPARE, 21, false );
104
105 /** Grant for {@link MicroOperation#FILTER_MATCH} */
106 public static final GrantAndDenial GRANT_FILTER_MATCH = new GrantAndDenial( MicroOperation.FILTER_MATCH, 22, true );
107
108 /** Denial for {@link MicroOperation#FILTER_MATCH} */
109 public static final GrantAndDenial DENY_FILTER_MATCH = new GrantAndDenial( MicroOperation.FILTER_MATCH, 23, false );
110
111 /** Grant for {@link MicroOperation#INVOKE} */
112 public static final GrantAndDenial GRANT_INVOKE = new GrantAndDenial( MicroOperation.INVOKE, 24, true );
113
114 /** Denial for {@link MicroOperation#INVOKE} */
115 public static final GrantAndDenial DENY_INVOKE = new GrantAndDenial( MicroOperation.INVOKE, 25, false );
116
117 private final MicroOperation microOperation;
118
119 private final int code;
120
121 private final String name;
122
123 private final boolean grant;
124
125
126 private GrantAndDenial(MicroOperation microOperation, int code, boolean grant)
127 {
128 this.microOperation = microOperation;
129 this.code = code;
130 this.name = ( grant ? "grant" : "deny" ) + microOperation.getName();
131 this.grant = grant;
132 }
133
134
135 /**
136 * Returns the {@link MicroOperation} related with this grant or denial.
137 */
138 public MicroOperation getMicroOperation()
139 {
140 return microOperation;
141 }
142
143
144 /**
145 * Return the code number of this grant or denial.
146 */
147 public int getCode()
148 {
149 return code;
150 }
151
152
153 /**
154 * Returns the name of this grant or denial.
155 */
156 public String getName()
157 {
158 return name;
159 }
160
161
162 /**
163 * Returns <tt>true</tt> if and only if this is grant.
164 */
165 public boolean isGrant()
166 {
167 return grant;
168 }
169
170
171 public String toString()
172 {
173 return name;
174 }
175 }