[jboss-cvs] JBossAS SVN: r105226 - in branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security: plugins and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 25 14:06:57 EDT 2010
Author: mmoyses
Date: 2010-05-25 14:06:57 -0400 (Tue, 25 May 2010)
New Revision: 105226
Modified:
branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/JNDIBasedSecurityManagement.java
branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/SecurityDomainObjectFactory.java
branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java
branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityManagerService.java
Log:
JBPAPP-4381: fixing setting of custom security manager
Modified: branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/JNDIBasedSecurityManagement.java
===================================================================
--- branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/JNDIBasedSecurityManagement.java 2010-05-25 17:42:38 UTC (rev 105225)
+++ branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/JNDIBasedSecurityManagement.java 2010-05-25 18:06:57 UTC (rev 105226)
@@ -73,14 +73,19 @@
protected String BASE_CTX = SecurityConstants.JAAS_CONTEXT_ROOT;
protected String authenticationMgrClass = "org.jboss.security.plugins.JaasSecurityManager";
+ protected static Class<?> authMgrClazz;
protected String authorizationMgrClass = "org.jboss.security.plugins.JBossAuthorizationManager";
+ protected static Class<?> authzMgrClazz;
protected String auditMgrClass = "org.jboss.security.plugins.audit.JBossAuditManager";
+ protected static Class<?> auditMgrClazz;
protected String identityTrustMgrClass = "org.jboss.security.plugins.identitytrust.JBossIdentityTrustManager";
+ protected static Class<?> idTrustMgrClazz;
protected String mappingMgrClass = "org.jboss.security.plugins.mapping.JBossMappingManager";
+ protected static Class<?> mapMgrClazz;
protected static transient CallbackHandler callBackHandler = new JBossCallbackHandler();
@@ -98,6 +103,8 @@
private transient ConcurrentHashMap<String,AuditManager> auditMgrMap = null;
private transient ConcurrentHashMap<String,IdentityTrustManager> idmMgrMap = null;
+ private static JNDIBasedSecurityManagement singleton = new JNDIBasedSecurityManagement();
+
public JNDIBasedSecurityManagement()
{
initialize();
@@ -108,17 +115,16 @@
params = {@ManagementParameter(name = "securityDomain", description = "The security domain name")})
public AuditManager getAuditManager(String securityDomain)
{
- initialize();
AuditManager auditManager = null;
try
{
- if(this.enableAudit)
+ if(singleton.enableAudit)
{
- auditManager = this.auditMgrMap.get(securityDomain);
+ auditManager = singleton.auditMgrMap.get(securityDomain);
if(auditManager == null)
{
auditManager = (AuditManager) lookUpJNDI(securityDomain + "/auditMgr");
- this.auditMgrMap.put(securityDomain, auditManager);
+ singleton.auditMgrMap.put(securityDomain, auditManager);
}
}
}
@@ -133,15 +139,14 @@
params = {@ManagementParameter(name = "securityDomain", description = "The security domain name")})
public AuthenticationManager getAuthenticationManager(String securityDomain)
{
- initialize();
AuthenticationManager am = null;
try
{
- am = this.authMgrMap.get(securityDomain);
+ am = singleton.authMgrMap.get(securityDomain);
if(am == null)
{
am = (AuthenticationManager) lookUpJNDI(securityDomain + "/authenticationMgr");
- this.authMgrMap.put(securityDomain, am);
+ singleton.authMgrMap.put(securityDomain, am);
}
}
catch(Exception e)
@@ -156,15 +161,14 @@
params = {@ManagementParameter(name = "securityDomain", description = "The security domain name")})
public AuthorizationManager getAuthorizationManager(String securityDomain)
{
- initialize();
AuthorizationManager am = null;
try
{
- am = this.authzMgrMap.get(securityDomain);
+ am = singleton.authzMgrMap.get(securityDomain);
if(am == null)
{
am = (AuthorizationManager) lookUpJNDI(securityDomain + "/authorizationMgr");
- this.authzMgrMap.put(securityDomain, am);
+ singleton.authzMgrMap.put(securityDomain, am);
}
}
catch(Exception e)
@@ -178,17 +182,16 @@
params = {@ManagementParameter(name = "securityDomain", description = "The security domain name")})
public IdentityTrustManager getIdentityTrustManager(String securityDomain)
{
- initialize();
IdentityTrustManager am = null;
try
{
- if(this.enableIdentity)
+ if(singleton.enableIdentity)
{
- am = this.idmMgrMap.get(securityDomain);
+ am = singleton.idmMgrMap.get(securityDomain);
if(am == null)
{
am = (IdentityTrustManager) lookUpJNDI(securityDomain + "/identityTrustMgr");
- this.idmMgrMap.put(securityDomain, am);
+ singleton.idmMgrMap.put(securityDomain, am);
}
}
}
@@ -203,15 +206,14 @@
params = {@ManagementParameter(name = "securityDomain", description = "The security domain name")})
public MappingManager getMappingManager(String securityDomain)
{
- initialize();
MappingManager am = null;
try
{
- am = this.mappingMgrMap.get(securityDomain);
+ am = singleton.mappingMgrMap.get(securityDomain);
if(am == null)
{
am = (MappingManager) lookUpJNDI(securityDomain + "/mappingMgr");
- this.mappingMgrMap.put(securityDomain, am);
+ singleton.mappingMgrMap.put(securityDomain, am);
}
}
catch(Exception e)
@@ -225,35 +227,40 @@
description = "The class that implements the AuthenticationManager interface")
public void setAuthenticationMgrClass(String authenticationMgrClass)
{
- this.authenticationMgrClass = authenticationMgrClass;
+ singleton.authenticationMgrClass = authenticationMgrClass;
+ authMgrClazz = null;
}
@ManagementProperty(use = {ViewUse.CONFIGURATION},
description = "The class that implements the AuthorizationManager interface")
public void setAuthorizationMgrClass(String authorizationMgrClass)
{
- this.authorizationMgrClass = authorizationMgrClass;
+ singleton.authorizationMgrClass = authorizationMgrClass;
+ authzMgrClazz = null;
}
@ManagementProperty(use = {ViewUse.CONFIGURATION},
description = "The class that implements the AuditManager interface")
public void setAuditMgrClass(String auditMgrClass)
{
- this.auditMgrClass = auditMgrClass;
+ singleton.auditMgrClass = auditMgrClass;
+ auditMgrClazz = null;
}
@ManagementProperty(use = {ViewUse.CONFIGURATION},
description = "The class that implements the IdentityTrustManager interface")
public void setIdentityTrustMgrClass(String identityTrustMgrClass)
{
- this.identityTrustMgrClass = identityTrustMgrClass;
+ singleton.identityTrustMgrClass = identityTrustMgrClass;
+ idTrustMgrClazz = null;
}
@ManagementProperty(use = {ViewUse.CONFIGURATION},
description = "The class that implements the MappingManager interface")
public void setMappingMgrClass(String mappingMgrClass)
{
- this.mappingMgrClass = mappingMgrClass;
+ singleton.mappingMgrClass = mappingMgrClass;
+ mapMgrClazz = null;
}
public void setCallBackHandler(CallbackHandler cbh)
@@ -264,24 +271,24 @@
public void setEnableAudit(boolean enableAudit)
{
- this.enableAudit = enableAudit;
+ singleton.enableAudit = enableAudit;
}
public void setEnableIdentity(boolean enableIdentity)
{
- this.enableIdentity = enableIdentity;
+ singleton.enableIdentity = enableIdentity;
}
public void setCachePolicy(CachePolicy cp)
{
- this.cachePolicy = cp;
+ singleton.cachePolicy = cp;
}
public void setBaseContext(String ctx)
{
if(ctx == null)
throw new IllegalArgumentException("ctx is null");
- this.BASE_CTX = ctx;
+ singleton.BASE_CTX = ctx;
}
/** Set the indicated security domain cache timeout. This only has an
@@ -344,19 +351,19 @@
{
log.debug("Creating SDC for domain="+securityDomain);
AuthenticationManager am = createAuthenticationManager(securityDomain);
- if(cachePolicy == null)
+ if(singleton.cachePolicy == null)
{
- cachePolicy = createDefaultCachePolicy();
+ singleton.cachePolicy = createDefaultCachePolicy();
}
//Set security cache if the auth manager implementation supports it
- setSecurityDomainCache(am, cachePolicy);
+ setSecurityDomainCache(am, singleton.cachePolicy);
//Set DeepCopySubject option if supported
if(SecurityConfiguration.isDeepCopySubjectMode())
{
setDeepCopySubjectMode(am);
}
- SecurityDomainContext securityDomainContext = new SecurityDomainContext(am, cachePolicy);
+ SecurityDomainContext securityDomainContext = new SecurityDomainContext(am, singleton.cachePolicy);
securityDomainContext.setAuthorizationManager(createAuthorizationManager(securityDomain));
securityDomainContext.setAuditMgr(createAuditManager(securityDomain));
@@ -378,15 +385,9 @@
{
String domainName = domain.getSecurityDomain();
SecurityDomainContext sdc = (SecurityDomainContext) securityMgrMap.get(domainName);
- if(sdc != null)
- {
- sdc.setAuthenticationManager(domain);
- }
- else
- {
+ if (sdc == null)
sdc = createSecurityDomainContext(domainName);
- sdc.setAuthenticationManager(domain);
- }
+ sdc.setAuthenticationManager(domain);
securityMgrMap.put(domainName, sdc);
}
@@ -440,37 +441,42 @@
private AuthenticationManager createAuthenticationManager(String securityDomain) throws Exception
{
- Class<?> clazz = SecurityActions.getContextClassLoader().loadClass(authenticationMgrClass);
- Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class, CallbackHandler.class});
- return (AuthenticationManager) ctr.newInstance(new Object[]{ securityDomain, callBackHandler});
+ if (authMgrClazz == null)
+ authMgrClazz = SecurityActions.getContextClassLoader().loadClass(singleton.authenticationMgrClass);
+ Constructor<?> ctr = authMgrClazz.getConstructor(new Class[] {String.class, CallbackHandler.class});
+ return (AuthenticationManager) ctr.newInstance(new Object[]{securityDomain, callBackHandler});
}
-
+
private AuthorizationManager createAuthorizationManager(String securityDomain) throws Exception
{
- Class<?> clazz = SecurityActions.getContextClassLoader().loadClass(authorizationMgrClass);
- Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class});
- return (AuthorizationManager) ctr.newInstance(new Object[]{ securityDomain});
+ if (authzMgrClazz == null)
+ authzMgrClazz = SecurityActions.getContextClassLoader().loadClass(singleton.authorizationMgrClass);
+ Constructor<?> ctr = authzMgrClazz.getConstructor(new Class[] {String.class});
+ return (AuthorizationManager) ctr.newInstance(new Object[]{securityDomain});
}
-
+
private AuditManager createAuditManager(String securityDomain) throws Exception
{
- Class<?> clazz = SecurityActions.getContextClassLoader().loadClass(auditMgrClass);
- Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class});
- return (AuditManager) ctr.newInstance(new Object[]{ securityDomain});
+ if (auditMgrClazz == null)
+ auditMgrClazz = SecurityActions.getContextClassLoader().loadClass(singleton.auditMgrClass);
+ Constructor<?> ctr = auditMgrClazz.getConstructor(new Class[] {String.class});
+ return (AuditManager) ctr.newInstance(new Object[]{securityDomain});
}
-
+
private MappingManager createMappingManager(String securityDomain) throws Exception
{
- Class<?> clazz = SecurityActions.getContextClassLoader().loadClass(mappingMgrClass);
- Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class});
- return (MappingManager) ctr.newInstance(new Object[]{ securityDomain});
+ if (mapMgrClazz == null)
+ mapMgrClazz = SecurityActions.getContextClassLoader().loadClass(singleton.mappingMgrClass);
+ Constructor<?> ctr = mapMgrClazz.getConstructor(new Class[] {String.class});
+ return (MappingManager) ctr.newInstance(new Object[]{securityDomain});
}
-
+
private IdentityTrustManager createIdentityTrustManager(String securityDomain) throws Exception
{
- Class<?> clazz = SecurityActions.getContextClassLoader().loadClass(identityTrustMgrClass);
- Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class});
- return (IdentityTrustManager) ctr.newInstance(new Object[]{ securityDomain});
+ if (idTrustMgrClazz == null)
+ idTrustMgrClazz = SecurityActions.getContextClassLoader().loadClass(singleton.identityTrustMgrClass);
+ Constructor<?> ctr = idTrustMgrClazz.getConstructor(new Class[] {String.class});
+ return (IdentityTrustManager) ctr.newInstance(new Object[]{securityDomain});
}
/** Use reflection to attempt to set the authentication cache on the
@@ -570,4 +576,9 @@
if(callBackHandler == null)
callBackHandler = new JBossCallbackHandler();
}
+
+ public static JNDIBasedSecurityManagement getInstance()
+ {
+ return singleton;
+ }
}
Modified: branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/SecurityDomainObjectFactory.java
===================================================================
--- branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/SecurityDomainObjectFactory.java 2010-05-25 17:42:38 UTC (rev 105225)
+++ branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/integration/SecurityDomainObjectFactory.java 2010-05-25 18:06:57 UTC (rev 105226)
@@ -51,7 +51,7 @@
*/
public class SecurityDomainObjectFactory implements InvocationHandler, ObjectFactory
{
- private JNDIBasedSecurityManagement securityManagement = new JNDIBasedSecurityManagement();
+ private JNDIBasedSecurityManagement securityManagement = JNDIBasedSecurityManagement.getInstance();
public void setSecurityManagement(JNDIBasedSecurityManagement sm)
{
@@ -170,4 +170,4 @@
//return domains.nextElement();
}
}
-}
\ No newline at end of file
+}
Modified: branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java
===================================================================
--- branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java 2010-05-25 17:42:38 UTC (rev 105225)
+++ branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityDomain.java 2010-05-25 18:06:57 UTC (rev 105226)
@@ -171,7 +171,7 @@
private String trustMgrFactoryAlgorithm;
/** Specify the SecurityManagement instance */
- private ISecurityManagement securityManagement = new JNDIBasedSecurityManagement();
+ private ISecurityManagement securityManagement = JNDIBasedSecurityManagement.getInstance();
/**
* Creates a default JaasSecurityDomain for with a securityDomain name of 'other'.
Modified: branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityManagerService.java
===================================================================
--- branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityManagerService.java 2010-05-25 17:42:38 UTC (rev 105225)
+++ branches/JBPAPP_5_0_0_JBAS-8025/security/src/main/org/jboss/security/plugins/JaasSecurityManagerService.java 2010-05-25 18:06:57 UTC (rev 105226)
@@ -161,6 +161,7 @@
securityMgrClass = loader.loadClass(securityMgrClassName);
if( AuthenticationManager.class.isAssignableFrom(securityMgrClass) == false )
throw new ClassCastException(securityMgrClass+" does not implement "+AuthenticationManager.class);
+ JNDIBasedSecurityManagement.getInstance().setAuthenticationMgrClass(securityMgrClassName);
}
public String getSecurityProxyFactoryClassName()
{
More information about the jboss-cvs-commits
mailing list