| 1 17 18 package org.sape.carbon.services.security.management; 19 20 import java.security.Principal ; 21 import java.security.acl.Group ; 22 import java.util.Collection ; 23 import java.util.Enumeration ; 24 import java.util.HashSet ; 25 import java.util.Map ; 26 import java.util.Set ; 27 28 import org.sape.carbon.core.component.ComponentConfiguration; 29 import org.sape.carbon.core.component.lifecycle.Configurable; 30 import org.sape.carbon.core.config.InvalidConfigurationException; 31 import org.sape.carbon.core.exception.InvalidParameterException; 32 33 51 public class DefaultUserManagerJmxAdapterImpl 52 implements UserManagerJmxAdapter, Configurable { 53 54 protected UserManagerJmxAdapterConfiguration config; 55 56 71 public void createUser(String userName, Map userInfo) 72 throws DuplicatePrincipalException, SecurityManagementDataStoreException { 73 if (userName == null) { 74 throw new InvalidParameterException( 75 this.getClass(), 76 "userName was an empty String"); 77 } 78 79 UserManager userManager = config.getUserManager(); 80 81 userManager.createUser(userName, userInfo); 82 } 83 84 94 public void removeUser(String userName) 95 throws UnknownPrincipalException, SecurityManagementDataStoreException { 96 if (userName == null) { 97 throw new InvalidParameterException( 98 this.getClass(), 99 "userName was an empty String"); 100 } 101 102 UserManager userManager = config.getUserManager(); 103 104 Principal user = userManager.retreiveUser(userName); 105 106 if (user == null) { 107 throw new UnknownPrincipalException( 108 this.getClass(), userName); 109 } 110 111 userManager.removeUser(user); 112 } 113 114 129 public void updatePassword(String userName, String password) 130 throws UnknownPrincipalException, SecurityManagementDataStoreException { 131 if (userName == null) { 132 throw new InvalidParameterException( 133 this.getClass(), 134 "userName was an empty String"); 135 } 136 137 UserManager userManager = config.getUserManager(); 138 139 Principal user = userManager.retreiveUser(userName); 140 141 if (user == null) { 142 throw new UnknownPrincipalException( 143 this.getClass(), 144 user.getName()); 145 } 146 147 userManager.updateCredential(user, password); 148 } 149 150 160 public void createGroup(String groupName) 161 throws DuplicateGroupException, SecurityManagementDataStoreException { 162 if (groupName == null) { 163 throw new InvalidParameterException( 164 this.getClass(), 165 "groupName was an empty String"); 166 } 167 168 UserManager userManager = config.getUserManager(); 169 170 userManager.createGroup(groupName); 171 } 172 173 183 public void removeGroup(String groupName) 184 throws UnknownGroupException, SecurityManagementDataStoreException { 185 if (groupName == null) { 186 throw new InvalidParameterException( 187 this.getClass(), 188 "groupName was an empty String"); 189 } 190 191 UserManager userManager = config.getUserManager(); 192 193 Group group = userManager.retreiveGroup(groupName); 194 195 if (group == null) { 196 throw new UnknownGroupException( 197 this.getClass(), group.getName()); 198 } 199 200 userManager.removeGroup(group); 201 } 202 203 218 public boolean addUserToGroup(String userName, String groupName) 219 throws UnknownPrincipalException, SecurityManagementDataStoreException { 220 if (userName == null) { 221 throw new InvalidParameterException( 222 this.getClass(), 223 "userName was an empty String"); 224 } 225 226 if (groupName == null) { 227 throw new InvalidParameterException( 228 this.getClass(), 229 "groupName was an empty String"); 230 } 231 232 boolean result = false; 233 UserManager userManager = config.getUserManager(); 234 235 Principal user = userManager.retreiveUser(userName); 236 237 if (user == null) { 238 throw new UnknownPrincipalException( 239 this.getClass(), user.getName()); 240 } 241 242 Group group = userManager.retreiveGroup(groupName); 243 244 if (group == null) { 245 throw new UnknownGroupException( 246 this.getClass(), group.getName()); 247 } 248 249 result = userManager.addPrincipalToGroup(user, group); 250 251 return result; 252 } 253 254 269 public boolean addGroupToGroup( 270 String childGroupName, String parentGroupName) 271 throws UnknownPrincipalException, UnknownGroupException, SecurityManagementDataStoreException { 272 if (childGroupName == null) { 273 throw new InvalidParameterException( 274 this.getClass(), 275 "childGroupName was an empty String"); 276 } 277 278 if (parentGroupName == null) { 279 throw new InvalidParameterException( 280 this.getClass(), 281 "parentGroupName was an empty String"); 282 } 283 284 boolean result = false; 285 UserManager userManager = config.getUserManager(); 286 287 Group childGroup = userManager.retreiveGroup(childGroupName); 288 289 if (childGroup == null) { 290 throw new UnknownGroupException( 291 this.getClass(), 292 childGroup.getName()); 293 } 294 295 Group parentGroup = userManager.retreiveGroup(parentGroupName); 296 297 if (parentGroup == null) { 298 throw new UnknownGroupException( 299 this.getClass(), 300 parentGroup.getName()); 301 } 302 303 result = userManager.addPrincipalToGroup(childGroup, parentGroup); 304 305 return result; 306 } 307 308 323 public boolean removeUserFromGroup(String userName, String groupName) 324 throws UnknownPrincipalException, UnknownGroupException, SecurityManagementDataStoreException { 325 if (userName == null) { 326 throw new InvalidParameterException( 327 this.getClass(), 328 "userName was an empty String"); 329 } 330 331 if (groupName == null) { 332 throw new InvalidParameterException( 333 this.getClass(), 334 "groupName was an empty String"); 335 } 336 337 boolean result = false; 338 UserManager userManager = config.getUserManager(); 339 340 Principal user = userManager.retreiveUser(userName); 341 342 if (user == null) { 343 throw new UnknownPrincipalException( 344 this.getClass(), 345 user.getName()); 346 } 347 348 Group group = userManager.retreiveGroup(groupName); 349 350 if (group == null) { 351 throw new UnknownGroupException( 352 this.getClass(), 353 group.getName()); 354 } 355 356 result = userManager.removePrincipalFromGroup(user, group); 357 358 return result; 359 } 360 361 376 public boolean removeGroupFromGroup( 377 String childGroupName, String parentGroupName) 378 throws UnknownGroupException, UnknownPrincipalException, SecurityManagementDataStoreException { 379 if (childGroupName == null) { 380 throw new InvalidParameterException( 381 this.getClass(), 382 "childGroupName was an empty String"); 383 } 384 385 if (parentGroupName == null) { 386 throw new InvalidParameterException( 387 this.getClass(), 388 "parentGroupName was an empty String"); 389 } 390 391 boolean result = false; 392 UserManager userManager = config.getUserManager(); 393 394 Group childGroup = userManager.retreiveGroup(childGroupName); 395 396 if (childGroup == null) { 397 throw new UnknownGroupException( 398 this.getClass(), 399 childGroup.getName()); 400 } 401 402 Group parentGroup = userManager.retreiveGroup(parentGroupName); 403 404 if (parentGroup == null) { 405 throw new UnknownGroupException( 406 this.getClass(), 407 parentGroup.getName()); 408 } 409 410 result = 411 userManager.removePrincipalFromGroup(childGroup, parentGroup); 412 413 return result; 414 } 415 416 421 public Set retreiveAllUserNames() throws SecurityManagementDataStoreException { 422 UserManager userManager = config.getUserManager(); 423 424 return userManager.retreiveAllUserNames(); 425 } 426 427 432 public Set retreiveAllGroupNames() throws SecurityManagementDataStoreException { 433 UserManager userManager = config.getUserManager(); 434 435 return userManager.retreiveAllGroupNames(); 436 } 437 438 450 public Collection retreiveAllMemberNames(String groupName) 451 throws UnknownGroupException, SecurityManagementDataStoreException { 452 if (groupName == null) { 453 throw new InvalidParameterException( 454 this.getClass(), 455 "groupName was an empty String"); 456 } 457 458 UserManager userManager = config.getUserManager(); 459 460 Group group = userManager.retreiveGroup(groupName); 461 462 if (group == null) { 463 throw new UnknownGroupException( 464 this.getClass(), 465 group.getName()); 466 } 467 468 Enumeration membersEnumeration = group.members(); 469 Set membersSet = new HashSet (); 470 471 while (membersEnumeration.hasMoreElements()) { 472 Principal member = 473 (Principal ) membersEnumeration.nextElement(); 474 475 membersSet.add(member.getName()); 476 } 477 478 return membersSet; 479 } 480 481 491 public void configure(ComponentConfiguration configuration) { 492 493 try { 494 this.config = 495 (UserManagerJmxAdapterConfiguration) configuration; 496 } catch (ClassCastException cce) { 497 throw new InvalidConfigurationException( 498 this.getClass(), configuration.getConfigurationName(), 499 "ComponentConfiguration", 500 "Specifed UserManagerJmxAdapterConfiguration does not " 501 + "implement correct interface.", 502 cce); 503 } 504 } 505 } 506 | Popular Tags |