Search in sources :

Example 1 with ClassLoaderLocator

use of org.jboss.security.plugins.ClassLoaderLocator in project jbossws-cxf by jbossws.

the class JBossWSClientAuthConfig method getAuthContext.

@SuppressWarnings({ "rawtypes", "unchecked" })
public ClientAuthContext getAuthContext(String authContextID, Subject clientSubject, Map properties) throws AuthException {
    List<ControlFlag> controlFlags = new ArrayList<ControlFlag>();
    Map<String, Map> mapOptionsByName = new HashMap<String, Map>();
    JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) properties.get("jaspi-policy");
    AuthModuleEntry[] amearr = jai.getAuthModuleEntry();
    ClassLoader moduleCL = null;
    String jbossModule = jai.getJBossModuleName();
    if (jbossModule != null && !jbossModule.isEmpty()) {
        ClassLoaderLocator locator = ClassLoaderLocatorFactory.get();
        if (locator != null)
            moduleCL = locator.get(jbossModule);
    }
    for (AuthModuleEntry ame : amearr) {
        try {
            mapOptionsByName.put(ame.getAuthModuleName(), ame.getOptions());
            controlFlags.add(ame.getControlFlag());
            ClientAuthModule sam = this.createCAM(moduleCL, ame.getAuthModuleName());
            Map options = new HashMap();
            sam.initialize(null, null, callbackHandler, options);
            modules.add(sam);
        } catch (Exception e) {
            throw new AuthException(e.getLocalizedMessage());
        }
    }
    JBossWSClientAuthContext clientAuthContext = new JBossWSClientAuthContext(modules, mapOptionsByName, this.callbackHandler);
    clientAuthContext.setControlFlags(controlFlags);
    return clientAuthContext;
}
Also used : AuthModuleEntry(org.jboss.security.auth.container.config.AuthModuleEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JASPIAuthenticationInfo(org.jboss.security.auth.login.JASPIAuthenticationInfo) AuthException(javax.security.auth.message.AuthException) SOAPException(javax.xml.soap.SOAPException) AuthException(javax.security.auth.message.AuthException) ControlFlag(org.jboss.security.config.ControlFlag) ClientAuthModule(javax.security.auth.message.module.ClientAuthModule) ClassLoaderLocator(org.jboss.security.plugins.ClassLoaderLocator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ClassLoaderLocator

use of org.jboss.security.plugins.ClassLoaderLocator in project jbossws-cxf by jbossws.

the class JBossWSServerAuthConfig method getAuthContext.

@SuppressWarnings({ "rawtypes", "unchecked" })
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject, Map properties) throws AuthException {
    List<ControlFlag> controlFlags = new ArrayList<ControlFlag>();
    Map<String, Map> mapOptionsByName = new HashMap<String, Map>();
    JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) properties.get("jaspi-policy");
    AuthModuleEntry[] amearr = jai.getAuthModuleEntry();
    ClassLoader moduleCL = null;
    String jbossModule = jai.getJBossModuleName();
    if (jbossModule != null && !jbossModule.isEmpty()) {
        ClassLoaderLocator locator = ClassLoaderLocatorFactory.get();
        if (locator != null)
            moduleCL = locator.get(jbossModule);
    }
    for (AuthModuleEntry ame : amearr) {
        if (ame.getLoginModuleStackHolderName() != null) {
            try {
                mapOptionsByName.put(ame.getAuthModuleName(), ame.getOptions());
                controlFlags.add(ame.getControlFlag());
                ServerAuthModule sam = this.createSAM(moduleCL, ame.getAuthModuleName(), ame.getLoginModuleStackHolderName());
                Map options = new HashMap();
                Bus bus = (Bus) properties.get(Bus.class);
                options.put(Bus.class, bus);
                javax.xml.ws.Endpoint endpoint = (javax.xml.ws.Endpoint) properties.get(javax.xml.ws.Endpoint.class);
                options.put(javax.xml.ws.Endpoint.class, endpoint);
                sam.initialize(null, null, callbackHandler, options);
                modules.add(sam);
            } catch (Exception e) {
                throw new AuthException(e.getLocalizedMessage());
            }
        } else {
            try {
                mapOptionsByName.put(ame.getAuthModuleName(), ame.getOptions());
                controlFlags.add(ame.getControlFlag());
                ServerAuthModule sam = this.createSAM(moduleCL, ame.getAuthModuleName());
                Map options = new HashMap();
                sam.initialize(null, null, callbackHandler, options);
                modules.add(sam);
            } catch (Exception e) {
                throw new AuthException(e.getLocalizedMessage());
            }
        }
    }
    JBossWSServerAuthContext serverAuthContext = new JBossWSServerAuthContext(modules, mapOptionsByName, this.callbackHandler);
    serverAuthContext.setControlFlags(controlFlags);
    return serverAuthContext;
}
Also used : AuthModuleEntry(org.jboss.security.auth.container.config.AuthModuleEntry) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JASPIAuthenticationInfo(org.jboss.security.auth.login.JASPIAuthenticationInfo) ServerAuthModule(javax.security.auth.message.module.ServerAuthModule) AuthException(javax.security.auth.message.AuthException) SOAPException(javax.xml.soap.SOAPException) AuthException(javax.security.auth.message.AuthException) ControlFlag(org.jboss.security.config.ControlFlag) ClassLoaderLocator(org.jboss.security.plugins.ClassLoaderLocator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AuthException (javax.security.auth.message.AuthException)2 SOAPException (javax.xml.soap.SOAPException)2 AuthModuleEntry (org.jboss.security.auth.container.config.AuthModuleEntry)2 JASPIAuthenticationInfo (org.jboss.security.auth.login.JASPIAuthenticationInfo)2 ControlFlag (org.jboss.security.config.ControlFlag)2 ClassLoaderLocator (org.jboss.security.plugins.ClassLoaderLocator)2 ClientAuthModule (javax.security.auth.message.module.ClientAuthModule)1 ServerAuthModule (javax.security.auth.message.module.ServerAuthModule)1 Bus (org.apache.cxf.Bus)1