001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 028 package org.opends.server.authorization.dseecompat; 029 import static org.opends.server.authorization.dseecompat.Aci.*; 030 031 /** 032 * This class provides an enumeration of the allowed rights. 033 */ 034 public enum EnumRight { 035 036 /** 037 * This enumeration is returned when the result of the right is "read". 038 */ 039 READ ("read"), 040 /** 041 * This enumeration is returned when the result of the right is "write". 042 */ 043 WRITE ("write"), 044 /** 045 * This enumeration is returned when the result of the right is "add". 046 */ 047 ADD ("add"), 048 /** 049 * This enumeration is returned when the result of the right is "delete". 050 */ 051 DELETE ("delete"), 052 /** 053 * This enumeration is returned when the result of the right is "search". 054 */ 055 SEARCH ("search"), 056 /** 057 * This enumeration is returned when the result of the right is "compare". 058 */ 059 COMPARE ("compare"), 060 /** 061 * This enumeration is returned when the result of the right is 062 * "selfwrite". 063 */ 064 SELFWRITE ("selfwrite"), 065 /** 066 * This enumeration is returned when the result of the right is "proxy". 067 */ 068 PROXY ("proxy"), 069 /** 070 * This enumeration is returned when the result of the right is "import". 071 */ 072 IMPORT ("import"), 073 /** 074 * This enumeration is returned when the result of the right is "export". 075 */ 076 EXPORT ("export"), 077 /** 078 * This enumeration is returned when the result of the right is "all". 079 */ 080 ALL ("all"), 081 /** 082 * This enumeration is used internally by the modify operation 083 * processing and is not part of the ACI syntax. 084 */ 085 DELWRITE ("delwrite"), 086 /** 087 * This enumerations is used internally by the modify operation 088 * processing and is not part of the ACI syntax. 089 */ 090 ADDWRITE ("addwrite"); 091 092 /* 093 * The name of the right. 094 */ 095 private final String right; 096 097 /** 098 * Creates an enumeration of the right name. 099 * @param right The name of the right. 100 */ 101 EnumRight (String right) { 102 this.right = right ; 103 } 104 105 /** 106 * Checks if the enumeration is equal to the right name. 107 * @param right The name of the right to check. 108 * @return True if the right is equal to the enumeration's. 109 */ 110 public boolean isRight(String right){ 111 return right.equalsIgnoreCase(this.right); 112 } 113 114 /** 115 * Creates an enumeration of the right name. 116 * @param right The name of the right. 117 * @return An enumeration of the right or null if the name is invalid. 118 */ 119 public static EnumRight decode(String right){ 120 if (right != null){ 121 for (EnumRight t : EnumRight.values()){ 122 if (t.isRight(right)){ 123 return t; 124 } 125 } 126 } 127 return null; 128 } 129 130 /** 131 * Returns bit mask associated with the specified right. 132 * @param right The right enumeration to return the mask for. 133 * @return The bit mask associated with the right. 134 */ 135 public static int getMask(EnumRight right) { 136 int mask=ACI_NULL; 137 switch(right) { 138 case READ: 139 mask=ACI_READ; 140 break; 141 case WRITE: 142 mask=ACI_WRITE; 143 break; 144 case ADD: 145 mask=ACI_ADD; 146 break; 147 case DELETE: 148 mask=ACI_DELETE; 149 break; 150 case SEARCH: 151 mask=ACI_SEARCH; 152 break; 153 case COMPARE: 154 mask=ACI_COMPARE; 155 break; 156 case ALL: 157 mask=ACI_ALL; 158 break; 159 case EXPORT: 160 mask=ACI_EXPORT; 161 break; 162 case IMPORT: 163 mask=ACI_IMPORT; 164 break; 165 case PROXY: 166 mask=ACI_PROXY; 167 break; 168 case SELFWRITE: 169 mask=ACI_SELF; 170 break; 171 } 172 return mask; 173 } 174 }