javax.security.auth.message.module.ServerAuthModule Java Examples

The following examples show how to use javax.security.auth.message.module.ServerAuthModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleServerAuthContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked") // JASPIC API uses raw types
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
        Subject serviceSubject) throws AuthException {
    for (int moduleIndex = 0; moduleIndex < modules.size(); moduleIndex++) {
        ServerAuthModule module = modules.get(moduleIndex);
        AuthStatus result = module.validateRequest(messageInfo, clientSubject, serviceSubject);
        if (result != AuthStatus.SEND_FAILURE) {
            messageInfo.getMap().put("moduleIndex", Integer.valueOf(moduleIndex));
            return result;
        }
    }
    return AuthStatus.SEND_FAILURE;
}
 
Example #2
Source File: JBossServerAuthConfig.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private ServerAuthModule createSAM(ClassLoader moduleCL, String name )
throws Exception
{
   Class clazz = SecurityActions.loadClass(moduleCL, name);
   Constructor ctr = clazz.getConstructor(new Class[0]);
   return (ServerAuthModule) ctr.newInstance(new Object[0]);
}
 
Example #3
Source File: JBossServerAuthConfig.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private ServerAuthModule createSAM(ClassLoader moduleCL, String name, String lmshName )
throws Exception
{
   Class clazz = SecurityActions.loadClass(moduleCL, name);
   Constructor ctr = clazz.getConstructor(new Class[]{String.class});
   return (ServerAuthModule) ctr.newInstance(new Object[]{lmshName});
}
 
Example #4
Source File: JBossServerAuthContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JBossServerAuthContext(List<ServerAuthModule> modules,
      Map<String,Map> moduleNameToOptions, CallbackHandler cbh) throws AuthException
{
   this.modules = modules;
   this.moduleOptionsByName = moduleNameToOptions;
   for(ServerAuthModule sam:modules)
   {
      sam.initialize(null, null, cbh, 
            moduleOptionsByName.get(sam.getClass().getName())); 
   }
}
 
Example #5
Source File: JBossServerAuthContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see ServerAuthContext#cleanSubject(javax.security.auth.message.MessageInfo, javax.security.auth.Subject)
 */
public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException
{ 
   for(ServerAuthModule sam:modules)
   {
      sam.cleanSubject(messageInfo, subject);
   }
}
 
Example #6
Source File: JBossServerAuthContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see ServerAuthContext#secureResponse(javax.security.auth.message.MessageInfo, javax.security.auth.Subject)
 */
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException
{ 
   AuthStatus status = null; 
   for(ServerAuthModule sam:modules)
   {
      status = sam.secureResponse(messageInfo, serviceSubject);
   }
   return status;
}
 
Example #7
Source File: JBossServerAuthContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see ServerAuthContext#validateRequest(javax.security.auth.message.MessageInfo, javax.security.auth.Subject, javax.security.auth.Subject)
 */
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, 
      Subject serviceSubject) throws AuthException
{ 
   List<ServerAuthModule> supportingModules = new ArrayList<ServerAuthModule>();
   
   Class requestType = messageInfo.getRequestMessage().getClass();
   Class[] requestInterfaces = requestType.getInterfaces(); 
   
   List<Class> intfaee = Arrays.asList(requestInterfaces);
   
   for(ServerAuthModule sam:modules)
   { 
      List<Class> supportedTypes = Arrays.asList(sam.getSupportedMessageTypes());
      
      //Check the interfaces
      for(Class clazz:intfaee)
      {
         if(supportedTypes.contains(clazz) && !supportingModules.contains(sam)) 
            supportingModules.add(sam);
      } 
      
      //Check the class type also
      if((supportedTypes.contains(Object.class) || supportedTypes.contains(requestType))
            && !supportingModules.contains(sam)) 
         supportingModules.add(sam); 
   }
   if(supportingModules.size() == 0)
      throw PicketBoxMessages.MESSAGES.noServerAuthModuleForRequestType(requestType);

   AuthStatus authStatus = invokeModules(messageInfo, clientSubject, serviceSubject);
   return authStatus;
}
 
Example #8
Source File: JaspiDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Supplier<ServerAuthModule> createServerAuthModuleSupplier(final String className, final String module) {
    return new Supplier<ServerAuthModule>() {

        @Override
        public ServerAuthModule get() {
            try {
            ClassLoader classLoader = ClassLoadingAttributeDefinitions.resolveClassLoader(module);
            Object sam =  classLoader.loadClass(className).newInstance();
            return ServerAuthModule.class.cast(sam);
            } catch (Exception e) {
              throw   ROOT_LOGGER.failedToCreateServerAuthModule(className, module, e);
            }
        }
    };
}
 
Example #9
Source File: TheServerAuthConfig.java    From tomee with Apache License 2.0 5 votes vote down vote up
public TheServerAuthConfig(String layer, String appContext, CallbackHandler handler,
                            Map<String, String> providerProperties, ServerAuthModule serverAuthModule) {
    this.layer = layer;
    this.appContext = appContext;
    this.handler = handler;
    this.providerProperties = providerProperties;
    this.serverAuthModule = serverAuthModule;
}
 
Example #10
Source File: SimpleServerAuthConfig.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"}) // JASPIC API uses raw types
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject,
        Map properties) throws AuthException {
    ServerAuthContext serverAuthContext = this.serverAuthContext;
    if (serverAuthContext == null) {
        synchronized (this) {
            if (this.serverAuthContext == null) {
                Map<String,String> mergedProperties = new HashMap<>();
                if (this.properties != null) {
                    mergedProperties.putAll(this.properties);
                }
                if (properties != null) {
                    mergedProperties.putAll(properties);
                }

                List<ServerAuthModule> modules = new ArrayList<>();
                int moduleIndex = 1;
                String key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
                String moduleClassName = mergedProperties.get(key);
                while (moduleClassName != null) {
                    try {
                        Class<?> clazz = Class.forName(moduleClassName);
                        ServerAuthModule module =
                                (ServerAuthModule) clazz.getConstructor().newInstance();
                        module.initialize(null, null, handler, mergedProperties);
                        modules.add(module);
                    } catch (ClassNotFoundException | InstantiationException |
                            IllegalAccessException | IllegalArgumentException |
                            InvocationTargetException | NoSuchMethodException |
                            SecurityException e) {
                        AuthException ae = new AuthException();
                        ae.initCause(e);
                        throw ae;
                    }

                    // Look for the next module
                    moduleIndex++;
                    key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
                    moduleClassName = mergedProperties.get(key);
                }

                if (modules.size() == 0) {
                    throw new AuthException(sm.getString("simpleServerAuthConfig.noModules"));
                }

                this.serverAuthContext = createServerAuthContext(modules);
            }
            serverAuthContext = this.serverAuthContext;
        }
    }

    return serverAuthContext;
}
 
Example #11
Source File: SimpleServerAuthConfig.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected ServerAuthContext createServerAuthContext(List<ServerAuthModule> modules) {
    return new SimpleServerAuthContext(modules);
}
 
Example #12
Source File: SimpleServerAuthContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public SimpleServerAuthContext(List<ServerAuthModule> modules) {
    this.modules = modules;
}
 
Example #13
Source File: SimpleServerAuthContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject)
        throws AuthException {
    ServerAuthModule module = modules.get(((Integer) messageInfo.getMap().get("moduleIndex")).intValue());
    return module.secureResponse(messageInfo, serviceSubject);
}
 
Example #14
Source File: SimpleServerAuthContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException {
    for (ServerAuthModule module : modules) {
        module.cleanSubject(messageInfo, subject);
    }
}
 
Example #15
Source File: TheServerAuthContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
public TheServerAuthContext(CallbackHandler handler, ServerAuthModule serverAuthModule) throws AuthException {
    this.serverAuthModule = serverAuthModule;
    serverAuthModule.initialize(null, null, handler, Collections.<String, String> emptyMap());
}
 
Example #16
Source File: TheAuthConfigProvider.java    From tomee with Apache License 2.0 4 votes vote down vote up
public TheAuthConfigProvider(final ServerAuthModule serverAuthModule) {
    this.serverAuthModule = serverAuthModule;
}