Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Allow configuration of multiple jboss modules when instantiating clas…
Browse files Browse the repository at this point in the history
…ses (the jboss module attribute is currently overridden if more than one picketbox module defines it, which ends up causing class loading failures)
  • Loading branch information
sguilhen committed Jul 14, 2015
1 parent a841fbf commit 66ca699
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 32 deletions.
Expand Up @@ -307,14 +307,14 @@ private boolean authenticate(Principal principal, Object credential, Subject the
if(theAppPolicy != null)
{
BaseAuthenticationInfo authInfo = theAppPolicy.getAuthenticationInfo();
String jbossModuleName = authInfo.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = authInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoader currentTccl = SubjectActions.getContextClassLoader();
ClassLoaderLocator theCLL = ClassLoaderLocatorFactory.get();
if(theCLL != null)
{
ClassLoader newTCCL = theCLL.get(jbossModuleName);
ClassLoader newTCCL = theCLL.get(jbossModuleNames);
if(newTCCL != null)
{
try
Expand Down
9 changes: 9 additions & 0 deletions security-jboss-sx/jbosssx/pom.xml
Expand Up @@ -112,6 +112,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
Expand Down Expand Up @@ -139,12 +140,12 @@ public ServerAuthContext getAuthContext(String authContextID,

// establish the module classloader if a jboss-module has been specified.
ClassLoader moduleCL = null;
String jbossModule = jai.getJBossModuleName();
if (jbossModule != null && !jbossModule.isEmpty())
Set<String> jbossModuleNames = jai.getJBossModuleNames();
if (!jbossModuleNames.isEmpty())
{
ClassLoaderLocator locator = ClassLoaderLocatorFactory.get();
if (locator != null)
moduleCL = locator.get(jbossModule);
moduleCL = locator.get(jbossModuleNames);
}

for(AuthModuleEntry ame: amearr)
Expand Down
Expand Up @@ -22,7 +22,9 @@
package org.jboss.security.config;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.security.auth.AuthPermission;

Expand All @@ -48,7 +50,7 @@ public abstract class BaseSecurityInfo<T>
* Name of the JBoss Module that can be optionally configured for
* custom login modules etc
*/
protected String jbossModuleName;
protected Set<String> jbossModuleNames = new HashSet<String>();

public BaseSecurityInfo()
{
Expand Down Expand Up @@ -94,18 +96,19 @@ public void setName(String name)
* Get the name of the JBoss Module
* @return
*/
public String getJBossModuleName()
public Set<String> getJBossModuleNames()
{
return jbossModuleName;
return jbossModuleNames;
}

/**
* Set the name of the JBoss Module
* @param jbossModuleName
*/
public void setJBossModuleName(String jbossModuleName)
public void addJBossModuleName(String jbossModuleName)
{
this.jbossModuleName = jbossModuleName;
if (jbossModuleName != null && !jbossModuleName.isEmpty())
this.jbossModuleNames.add(jbossModuleName);
}

protected abstract BaseSecurityInfo<T> create(String name);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.Set;

import javax.security.auth.login.LoginException;

Expand Down Expand Up @@ -107,13 +108,13 @@ private void initializeModules() throws Exception
IdentityTrustInfo iti = aPolicy.getIdentityTrustInfo();
if(iti == null)
return;
String jbossModuleName = iti.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = iti.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
if(cll != null)
{
moduleCL = cll.get(jbossModuleName);
moduleCL = cll.get(jbossModuleNames);
}
}
IdentityTrustModuleEntry[] itmearr = iti.getIdentityTrustModuleEntry();
Expand Down
Expand Up @@ -21,6 +21,9 @@
*/
package org.jboss.security.plugins;

import java.util.HashSet;
import java.util.Set;

/**
* An interface to locate a {@code ClassLoader}}
* The primary use of this interface is in the JBoss Application Server,
Expand All @@ -31,9 +34,15 @@
public interface ClassLoaderLocator
{
/**
* Given a key, return a {@code ClassLoader}
* @param key
* @return
* Given a module name, return a {@code ClassLoader}
* @param module the name of the module for which we want a {@link ClassLoader}.
* @return the module {@link java.lang.ClassLoader}.
*/
ClassLoader get(String key);
default ClassLoader get(String module) {
Set<String> modules = new HashSet<>();
modules.add(module);
return get(modules);
}

ClassLoader get(Set<String> modules);
}
Expand Up @@ -9,6 +9,7 @@
import java.security.PrivilegedActionException;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -64,13 +65,13 @@ public AuditContext getAuditContext() throws PrivilegedActionException
AuditInfo ai = ap.getAuditInfo();
if(ai != null)
{
String jbossModuleName = ai.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = ai.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
if(cll != null)
{
moduleCL = cll.get(jbossModuleName);
moduleCL = cll.get(jbossModuleNames);
}
}
ac = instantiate(moduleCL, ai);
Expand Down
Expand Up @@ -292,14 +292,14 @@ private boolean authenticate(Principal principal, Object credential,
if(theAppPolicy != null)
{
BaseAuthenticationInfo authInfo = theAppPolicy.getAuthenticationInfo();
String jbossModuleName = authInfo.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = authInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoader currentTccl = SubjectActions.getContextClassLoader();
ClassLoaderLocator theCLL = ClassLoaderLocatorFactory.get();
if(theCLL != null)
{
ClassLoader newTCCL = theCLL.get(jbossModuleName);
ClassLoader newTCCL = theCLL.get(jbossModuleNames);
if(newTCCL != null)
{
try
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
Expand Down Expand Up @@ -181,13 +182,13 @@ private void initializeModules(Resource resource, RoleGroup role, List<Authoriza
throw PicketBoxMessages.MESSAGES.failedToObtainAuthorizationInfo(securityDomainName);

ClassLoader moduleCL = null;
String jbossModuleName = authzInfo.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = authzInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
if( cll != null)
{
moduleCL = cll.get(jbossModuleName);
moduleCL = cll.get(jbossModuleNames);
}
}
AuthorizationModuleEntry[] entries = authzInfo.getAuthorizationModuleEntry();
Expand Down
Expand Up @@ -22,6 +22,7 @@
package org.jboss.security.plugins.mapping;

import java.util.ArrayList;
import java.util.Set;

import org.jboss.security.PicketBoxLogger;
import org.jboss.security.PicketBoxMessages;
Expand Down Expand Up @@ -101,13 +102,13 @@ public <T> MappingContext<T> getMappingContext(Class<T> mappingType)
private <T> MappingContext<T> generateMappingContext(MappingContext<T> mc, MappingInfo rmi)
{
ClassLoader moduleCL = null;
String jbossModuleName = rmi.getJBossModuleName();
if(jbossModuleName != null)
Set<String> jbossModuleNames = rmi.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
if(cll != null)
{
moduleCL = cll.get(jbossModuleName);
moduleCL = cll.get(jbossModuleNames);
}
}
MappingModuleEntry[] mpe = rmi.getMappingModuleEntry();
Expand Down
Expand Up @@ -21,6 +21,8 @@
*/
package org.jboss.test.authorization;

import java.util.Set;

import org.jboss.security.config.ApplicationPolicy;
import org.jboss.security.config.AuthorizationInfo;
import org.jboss.security.config.SecurityConfiguration;
Expand All @@ -41,13 +43,13 @@ protected void setSecurityConfiguration() throws Exception
super.setSecurityConfiguration();
ApplicationPolicy ap = SecurityConfiguration.getApplicationPolicy("other");
AuthorizationInfo ai = ap.getAuthorizationInfo();
ai.setJBossModuleName("org.picketbox");
ai.addJBossModuleName("org.picketbox");
ap.setAuthorizationInfo(ai);
SecurityConfiguration.addApplicationPolicy(ap);

ClassLoaderLocatorFactory.set(new ClassLoaderLocator() {

public ClassLoader get(String key) {
public ClassLoader get(Set<String> modules) {
return Thread.currentThread().getContextClassLoader();
}
});
Expand Down

0 comments on commit 66ca699

Please sign in to comment.