1 31 32 package org.opencms.security; 33 34 import java.util.StringTokenizer ; 35 36 45 public class CmsPermissionSetCustom extends CmsPermissionSet { 46 47 50 public CmsPermissionSetCustom() { 51 52 super(); 53 } 54 55 63 public CmsPermissionSetCustom(CmsPermissionSet permissions) { 64 65 m_allowed = permissions.m_allowed; 66 m_denied = permissions.m_denied; 67 } 68 69 74 public CmsPermissionSetCustom(int allowedPermissions) { 75 76 super(allowedPermissions); 77 78 } 79 80 86 public CmsPermissionSetCustom(int allowedPermissions, int deniedPermissions) { 87 88 super(allowedPermissions, deniedPermissions); 89 } 90 91 99 public CmsPermissionSetCustom(String permissionString) { 100 101 StringTokenizer tok = new StringTokenizer (permissionString, "+-", true); 102 m_allowed = 0; 103 m_denied = 0; 104 105 while (tok.hasMoreElements()) { 106 String prefix = tok.nextToken(); 107 String suffix = tok.nextToken(); 108 switch (suffix.charAt(0)) { 109 case 'R': 110 case 'r': 111 if (prefix.charAt(0) == '+') { 112 m_allowed |= CmsPermissionSet.PERMISSION_READ; 113 } 114 if (prefix.charAt(0) == '-') { 115 m_denied |= CmsPermissionSet.PERMISSION_READ; 116 } 117 break; 118 case 'W': 119 case 'w': 120 if (prefix.charAt(0) == '+') { 121 m_allowed |= CmsPermissionSet.PERMISSION_WRITE; 122 } 123 if (prefix.charAt(0) == '-') { 124 m_denied |= CmsPermissionSet.PERMISSION_WRITE; 125 } 126 break; 127 case 'V': 128 case 'v': 129 if (prefix.charAt(0) == '+') { 130 m_allowed |= CmsPermissionSet.PERMISSION_VIEW; 131 } 132 if (prefix.charAt(0) == '-') { 133 m_denied |= CmsPermissionSet.PERMISSION_VIEW; 134 } 135 break; 136 case 'C': 137 case 'c': 138 if (prefix.charAt(0) == '+') { 139 m_allowed |= CmsPermissionSet.PERMISSION_CONTROL; 140 } 141 if (prefix.charAt(0) == '-') { 142 m_denied |= CmsPermissionSet.PERMISSION_CONTROL; 143 } 144 break; 145 case 'D': 146 case 'd': 147 if (prefix.charAt(0) == '+') { 148 m_allowed |= CmsPermissionSet.PERMISSION_DIRECT_PUBLISH; 149 } 150 if (prefix.charAt(0) == '-') { 151 m_denied |= CmsPermissionSet.PERMISSION_DIRECT_PUBLISH; 152 } 153 break; 154 default: 155 break; 157 } 158 } 159 } 160 161 166 public void addPermissions(CmsPermissionSet permissionSet) { 167 168 m_allowed |= permissionSet.m_allowed; 169 m_denied |= permissionSet.m_denied; 170 } 171 172 177 public Object clone() { 178 179 return new CmsPermissionSetCustom(m_allowed, m_denied); 180 } 181 182 187 public void denyPermissions(int permissions) { 188 189 m_denied |= permissions; 190 } 191 192 197 public void grantPermissions(int permissions) { 198 199 m_allowed |= permissions; 200 } 201 202 208 public void setPermissions(CmsPermissionSet permissionSet) { 209 210 m_allowed = permissionSet.m_allowed; 211 m_denied = permissionSet.m_denied; 212 } 213 214 221 public void setPermissions(int allowedPermissions, int deniedPermissions) { 222 223 m_allowed = allowedPermissions; 224 m_denied = deniedPermissions; 225 } 226 227 } | Popular Tags |