Permalink
Browse files

WF-1600: Reading caseSensitive property from realms bean instead for …

…securityprovider at securityConfig.xml
  • Loading branch information...
1 parent 24100de commit ec8b326a581c4f1fb4aa7877fb6b7a8aadf832d9 Himanshu Mishra committed Feb 25, 2013
@@ -49,7 +49,8 @@
*/
private String _defaultRealm = "default";
-
+ private boolean caseSensitive = false;
+
public Realms()
{
// nothing
@@ -66,7 +67,7 @@ public void setSecurityProviders( List<SecurityProvider> providers )
String[] realms = provider.getRealms();
for ( int i=0; i<realms.length; i++ ) {
// _realms.put( realms[i].toLowerCase(), provider );
- if(provider instanceof SimpleSecurityProvider && !((SimpleSecurityProvider) provider).getDatabase().isCaseSensitive())
+ if(!caseSensitive)
_realms.put(realms[i].toLowerCase(), provider );
else
_realms.put( realms[i], provider );
@@ -111,7 +112,7 @@ public SecurityProvider getSecurityProvider( String realm )
if ( realm == null || realm.length() == 0 ) {
realm = _defaultRealm;
}
- if (_realms.get("") instanceof SimpleSecurityProvider && !((SimpleSecurityProvider)_realms.get("")).getDatabase().isCaseSensitive())
+ if (!caseSensitive)
realm = realm.toLowerCase();
return _realms.get( realm );
@@ -530,4 +531,12 @@ public boolean isWorkflowAdmin( String user )
return getRBACQuery( realm ).getUsers(realm);
}
+
+ public boolean isCaseSensitive() {
+ return caseSensitive;
+ }
+
+ public void setCaseSensitive(boolean caseSensitive) {
+ this.caseSensitive = caseSensitive;
+ }
}
@@ -128,7 +128,7 @@ public String createToken(String user, String password) throws RBACException, Re
// user = IdentifierUtils.normalize(user, _realms.getDefaultRealm(), false, '\\');
boolean caseSensitive = true;
String realms = (IdentifierUtils.getRealm(user).equals(""))?_realms.getDefaultRealm():IdentifierUtils.getRealm(user);
- caseSensitive = _realms.getSecurityProvider(realms).isCaseSensitive();
+ caseSensitive = _realms.isCaseSensitive();
user = IdentifierUtils.normalize(user, _realms.getDefaultRealm(), caseSensitive, '\\');
// place session information in token
@@ -230,7 +230,7 @@ public String authenticateUser(String user, Property[] credentials) throws Authe
if (rolesForUser == null) {
try {
String roles = StringArrayUtils.toCommaDelimited(_realms.authorizedRoles(user));
- boolean caseSensitive = _realms.getSecurityProvider(IdentifierUtils.getRealm(user)).isCaseSensitive();
+ boolean caseSensitive = _realms.isCaseSensitive();
if(!caseSensitive)
roles = roles.toLowerCase();
rolesForUser = new Property(AuthenticationConstants.PROPERTY_ROLES, roles);
@@ -65,8 +65,6 @@
private Map<String,LDAPRBACProvider> _rbacs;
private Map<String,LDAPAuthenticationProvider> _auths;
-
- private boolean caseSensitive = false;
/**
* Constructor
@@ -371,13 +369,4 @@ static final void close(Context context) {
properties.remove(id);
return properties;
}
-
- public void setCaseSensitive(boolean caseSensitive) {
- this.caseSensitive = caseSensitive;
- }
-
- @Override
- public boolean isCaseSensitive() {
- return caseSensitive;
- }
}
@@ -101,9 +101,4 @@ public void dispose()
* @throws RBACException
*/
public Set<String> getAttributes(String forObject) throws RBACException;
-
- /**
- * Return the boolean value indicating whether security provider is case sensitive or not.
- */
- public boolean isCaseSensitive();
}
@@ -9,11 +9,16 @@
package org.intalio.tempo.security.simple;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+
+import org.dom4j.Document;
+import org.dom4j.Node;
+import org.dom4j.io.SAXReader;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Unmarshaller;
import org.xml.sax.InputSource;
@@ -37,7 +42,7 @@
*/
private static final String MAPPING_FILE =
"/org/intalio/tempo/security/simple/SimpleDatabase.properties";
-
+ public static final String CONFIG_DIR_PROPERTY = "org.intalio.tempo.configDirectory";
/**
* Loaded mapping
@@ -50,13 +55,11 @@
*/
private HashMap<String,SimpleRealm> _realms;
-
/**
* Whether identifiers are case-sensitive.
*/
private static boolean _caseSensitive = false;
-
-
+
/**
* Realm separator character.
*/
@@ -67,30 +70,21 @@
* Default realm.
*/
private String _defaultRealm = "";
-
-
+
/**
* Default constructor used for marshalling.
*/
public SimpleDatabase()
{
_realms = new HashMap<String,SimpleRealm>();
}
-
-
- /**
- * Checks if simple security is caseSensitive
- * @return
- */
- public static boolean isCaseSensitive(){
- return _caseSensitive;
- }
- /**
- * Sets value for caseSensitive
+ /**
+ * Checks if simple security is caseSensitive
+ * @return
*/
- public static void setCaseSensitive(boolean caseSensetive) {
- _caseSensitive = caseSensetive;
+ public static boolean isCaseSensitive(){
+ return _caseSensitive;
}
/**
@@ -317,4 +311,23 @@ public void normalize( String[] identifiers )
identifiers[ i ] = normalize( identifiers[ i ] );
}
}
+
+ static {
+ String configDir = System.getProperty(CONFIG_DIR_PROPERTY);
+ if (configDir == null) {
+ throw new RuntimeException("System property " + CONFIG_DIR_PROPERTY + " not defined.");
+ }
+ File _configDir = new File(configDir, "securityConfig.xml");
+ if (!_configDir.exists()) {
+ throw new RuntimeException("Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist.");
+ }
+
+ try {
+ Document doc = new SAXReader().read(_configDir);
+ Node node = doc.selectSingleNode("//*[@name='caseSensitive']/value");
+ _caseSensitive = "true".equalsIgnoreCase(node.getText());
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to find caseSensitive property in securityConfig.xml file",e);
+ }
+ }
}
@@ -58,8 +58,6 @@
*/
private HashMap<String,RBACProvider> _rbacMap;
- private boolean caseSensitive = false;
-
/**
* Authentication providders: Map of { String, AuthenticationProvider }.
*/
@@ -244,23 +242,22 @@ public RBACProvider getRBACProvider( String realm )
{
if (!_rbacMap.containsKey(realm))
throw new RBACException("Realm, "+realm+", is not supported by this Security Provider!");
-// return (RBACProvider) _rbacMap.get( realm.toLowerCase() );
- if(_database.isCaseSensitive())
+ if (SimpleDatabase.isCaseSensitive())
return (RBACProvider) _rbacMap.get( realm );
- else
- return (RBACProvider) _rbacMap.get( realm.toLowerCase() );
+ else
+ return (RBACProvider) _rbacMap.get( realm.toLowerCase() );
}
// implement SecurityProvider interface
public AuthenticationProvider getAuthenticationProvider( String realm )
throws AuthenticationException
{
-// return (AuthenticationProvider) _authMap.get( realm.toLowerCase() );
- if(!_database.isCaseSensitive())
+// return (AuthenticationProvider) _authMap.get( realm.toLowerCase() );
+ if (SimpleDatabase.isCaseSensitive())
+ return (AuthenticationProvider) _authMap.get( realm );
+ else
return (AuthenticationProvider) _authMap.get( realm.toLowerCase() );
- else
- return (AuthenticationProvider) _authMap.get( realm );
}
@@ -312,7 +309,6 @@ private void reloadDatabase()
LOG.info( "Reload security database " + _filename );
}
try {
- SimpleDatabase.setCaseSensitive(caseSensitive);
_database = SimpleDatabase.load( getConfigStream() );
} catch ( Exception except ) {
LOG.error( "Error reloading security database " + _filename, except );
@@ -327,14 +323,14 @@ private void reloadDatabase()
// _rbacMap.put( realms[i].toLowerCase(), rbac );
auth = new SimpleAuthenticationProvider( realms[i] );
-// _authMap.put( realms[i].toLowerCase(), auth );
- if(_database.isCaseSensitive()){
- _rbacMap.put( realms[i], rbac );
- _authMap.put( realms[i], auth );
- }else{
- _rbacMap.put( realms[i].toLowerCase(), rbac );
- _authMap.put( realms[i].toLowerCase(), auth );
- }
+// _authMap.put( realms[i].toLowerCase(), auth );
+ if (SimpleDatabase.isCaseSensitive()) {
+ _rbacMap.put( realms[i], rbac );
+ _authMap.put( realms[i], auth );
+ } else {
+ _rbacMap.put( realms[i].toLowerCase(), rbac );
+ _authMap.put( realms[i].toLowerCase(), auth );
+ }
}
@@ -453,13 +449,4 @@ public AuthenticationRuntime getRuntime()
return properties;
}
- public void setCaseSensitive(boolean caseSensitive) {
- this.caseSensitive = caseSensitive;
- }
-
- @Override
- public boolean isCaseSensitive() {
- return caseSensitive;
- }
-
}
@@ -50,11 +50,4 @@ public void setName(String name) {
// TODO Auto-generated method stub
return null;
}
-
- @Override
- public boolean isCaseSensitive() {
- // TODO Auto-generated method stub
- return false;
- }
-
}

0 comments on commit ec8b326

Please sign in to comment.