View Javadoc
1 /* 2 * Copyright (c) 2003 3 * Information Desire GmbH 4 * All rights reserved. 5 */ 6 package com.infodesire.infobit.security; 7 8 import java.util.List; 9 import java.util.Collection; 10 import java.util.Properties; 11 import java.util.Iterator; 12 import java.util.HashSet; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 17 /*** 18 * default security provider. hardwired user configuration off properties 19 * 20 * @author konstantin 21 * @created August 7, 2003 22 * @version $Revision: 1.2 $ 23 */ 24 public class DefaultSecurityProvider implements SecurityProvider { 25 /*** 26 * property configuring username of this provider 27 */ 28 public final static String USERNAME_PROPERTY = "security.username"; 29 /*** 30 * property name prefix specifying user role ( can be used more than once ) 31 * good choice would be adding sequencial number 32 */ 33 public final static String ROLE_PROPERTY_PREFIX = "security.role."; 34 /*** 35 * property holding superuser role name. Only superusers can modify ACL 36 */ 37 private final static String SUPERUSER_ROLE = "infobit_superuser"; 38 39 private static Log _log = LogFactory.getLog(DefaultSecurityProvider.class); 40 41 private HashSet _roles = new HashSet(); 42 private String _userName = null; 43 44 45 /*** 46 * configured user name 47 * 48 * @return The Name value 49 */ 50 public String getName() { 51 return _userName; 52 } 53 54 55 /*** 56 * Gets the Superuser attribute of the DefaultSecurityProvider object 57 * 58 * @return The Superuser value 59 */ 60 public boolean isSuperuser() { 61 return hasRole(SUPERUSER_ROLE); 62 } 63 64 65 /*** 66 * whether provider configured to accept this role 67 * 68 * @param role role name of interest 69 * @return acceptance status 70 */ 71 public boolean hasRole(String role) { 72 return _roles.contains(role); 73 } 74 75 76 /*** 77 * whether provider configured to at least one of given roles 78 * 79 * @param roles Description of Parameter 80 * @return Description of the Returned Value 81 */ 82 public boolean hasRole(Collection roles) { 83 for (Iterator iter = roles.iterator(); iter.hasNext(); ) { 84 if (_roles.contains(iter.next())) { 85 return true; 86 } 87 } 88 return false; 89 } 90 91 92 /*** 93 * initialize security provider ( user & role set ) via properties. 94 * 95 * @param properties Description of Parameter 96 */ 97 public void init(Properties properties) { 98 if (properties != null) { 99 String pname; 100 for (Iterator iter = properties.keySet().iterator(); iter.hasNext(); ) { 101 pname = (String) iter.next(); 102 if (pname.startsWith(ROLE_PROPERTY_PREFIX)) { 103 _roles.add(properties.getProperty(pname)); 104 if (_log.isDebugEnabled()) { 105 _log.debug("configuring role: " + properties.getProperty(pname)); 106 } 107 } 108 else if (USERNAME_PROPERTY.equals(pname)) { 109 _userName = properties.getProperty(pname); 110 if (_log.isDebugEnabled()) { 111 _log.debug("configuring user: " + properties.getProperty(pname)); 112 } 113 114 } 115 } 116 } 117 } 118 }

This page was automatically generated by Maven