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

Commit

Permalink
Rework the support for multiple jboss modules to ensure API compatibi…
Browse files Browse the repository at this point in the history
…lity with previous versions.
  • Loading branch information
sguilhen committed Aug 30, 2016
1 parent cd7033c commit 548af1f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 36 deletions.
Expand Up @@ -22,13 +22,13 @@
package org.jboss.security.authentication;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.Principal;
import java.security.acl.Group;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -307,7 +307,7 @@ private boolean authenticate(Principal principal, Object credential, Subject the
if(theAppPolicy != null)
{
BaseAuthenticationInfo authInfo = theAppPolicy.getAuthenticationInfo();
Set<String> jbossModuleNames = authInfo.getJBossModuleNames();
List<String> jbossModuleNames = authInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoader currentTccl = SubjectActions.getContextClassLoader();
Expand Down
Expand Up @@ -26,7 +26,6 @@
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 @@ -140,7 +139,7 @@ public ServerAuthContext getAuthContext(String authContextID,

// establish the module classloader if a jboss-module has been specified.
ClassLoader moduleCL = null;
Set<String> jbossModuleNames = jai.getJBossModuleNames();
List<String> jbossModuleNames = jai.getJBossModuleNames();
if (!jbossModuleNames.isEmpty())
{
ClassLoaderLocator locator = ClassLoaderLocatorFactory.get();
Expand Down
Expand Up @@ -22,9 +22,8 @@
package org.jboss.security.config;

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

import javax.security.auth.AuthPermission;

Expand All @@ -44,13 +43,12 @@ public abstract class BaseSecurityInfo<T>

protected String name;

protected ArrayList<T> moduleEntries = new ArrayList<T>();
protected List<T> moduleEntries = new ArrayList<T>();

/**
* Name of the JBoss Module that can be optionally configured for
* custom login modules etc
* New implementation - allow the specification of multiple jboss module names.
*/
protected Set<String> jbossModuleNames = new HashSet<String>();
protected List<String> jbossModuleNames = new ArrayList<String>();

public BaseSecurityInfo()
{
Expand Down Expand Up @@ -96,15 +94,42 @@ public void setName(String name)
* Get the name of the JBoss Module
* @return
*/
public Set<String> getJBossModuleNames()
{
return jbossModuleNames;
@Deprecated
public String getJBossModuleName() {
if (!this.jbossModuleNames.isEmpty())
return this.jbossModuleNames.get(0);
return null;
}

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

/**
* Obtains the list of all configured jboss module names.
*
* @return the {@link List} containing all configured jboss module names.
*/
public List<String> getJBossModuleNames()
{
return Collections.unmodifiableList(this.jbossModuleNames);
}

/**
* Adds a new jboss module name.
*
* @param jbossModuleName the name of the module to be added.
*/
public void addJBossModuleName(String jbossModuleName)
{
if (jbossModuleName != null && !jbossModuleName.isEmpty())
Expand Down
Expand Up @@ -24,8 +24,8 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.security.auth.login.LoginException;

Expand Down Expand Up @@ -108,7 +108,7 @@ private void initializeModules() throws Exception
IdentityTrustInfo iti = aPolicy.getIdentityTrustInfo();
if(iti == null)
return;
Set<String> jbossModuleNames = iti.getJBossModuleNames();
List<String> jbossModuleNames = iti.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
Expand Down
Expand Up @@ -21,11 +21,10 @@
*/
package org.jboss.security.plugins;

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

/**
* An interface to locate a {@code ClassLoader}}
* An interface to locate a {@code ClassLoader}
* The primary use of this interface is in the JBoss Application Server,
* which needs to inject a module class loader for custom login modules etc
* @author Anil Saldhana
Expand All @@ -34,15 +33,24 @@
public interface ClassLoaderLocator
{
/**
* Given a module name, return a {@code ClassLoader}
* Given a module name, return a {@link ClassLoader}
* @param module the name of the module for which we want a {@link ClassLoader}.
* @return the module {@link java.lang.ClassLoader}.
*/
default ClassLoader get(String module) {
Set<String> modules = new HashSet<>();
modules.add(module);
return get(modules);
}
ClassLoader get(String module);

ClassLoader get(Set<String> modules);
/**
* Given a list of module names, return a {@link ClassLoader} that combines all module loaders. This method was made
* default to ensure API compatibility in WildFly. Implementations that are meant to provide support for multiple modules
* must override this default method implementation, which uses only the first module found in the list.
*
* @param modules the set of modules for which we want a {@link ClassLoader}.
* @return the combined {@link ClassLoader}
*/
default ClassLoader get(List<String> modules) {
if (modules != null && modules.size() > 0) {
return this.get(modules.get(0));
}
return null;
}
}
Expand Up @@ -9,7 +9,6 @@
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 @@ -65,7 +64,7 @@ public AuditContext getAuditContext() throws PrivilegedActionException
AuditInfo ai = ap.getAuditInfo();
if(ai != null)
{
Set<String> jbossModuleNames = ai.getJBossModuleNames();
List<String> jbossModuleNames = ai.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.Principal;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -292,7 +293,7 @@ private boolean authenticate(Principal principal, Object credential,
if(theAppPolicy != null)
{
BaseAuthenticationInfo authInfo = theAppPolicy.getAuthenticationInfo();
Set<String> jbossModuleNames = authInfo.getJBossModuleNames();
List<String> jbossModuleNames = authInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoader currentTccl = SubjectActions.getContextClassLoader();
Expand Down
Expand Up @@ -27,7 +27,6 @@
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 @@ -182,7 +181,7 @@ private void initializeModules(Resource resource, RoleGroup role, List<Authoriza
throw PicketBoxMessages.MESSAGES.failedToObtainAuthorizationInfo(securityDomainName);

ClassLoader moduleCL = null;
Set<String> jbossModuleNames = authzInfo.getJBossModuleNames();
List<String> jbossModuleNames = authzInfo.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
Expand Down
Expand Up @@ -22,7 +22,7 @@
package org.jboss.security.plugins.mapping;

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

import org.jboss.security.PicketBoxLogger;
import org.jboss.security.PicketBoxMessages;
Expand Down Expand Up @@ -102,7 +102,7 @@ public <T> MappingContext<T> getMappingContext(Class<T> mappingType)
private <T> MappingContext<T> generateMappingContext(MappingContext<T> mc, MappingInfo rmi)
{
ClassLoader moduleCL = null;
Set<String> jbossModuleNames = rmi.getJBossModuleNames();
List<String> jbossModuleNames = rmi.getJBossModuleNames();
if(!jbossModuleNames.isEmpty())
{
ClassLoaderLocator cll = ClassLoaderLocatorFactory.get();
Expand Down
Expand Up @@ -21,8 +21,6 @@
*/
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 @@ -49,7 +47,7 @@ protected void setSecurityConfiguration() throws Exception

ClassLoaderLocatorFactory.set(new ClassLoaderLocator() {

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

0 comments on commit 548af1f

Please sign in to comment.