static T newAuthModule()

in geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/impl/ConfigProviderImpl.java [244:272]


    static <T> T newAuthModule(final AuthModuleType authModuleType, final CallbackHandler callbackHandler) throws AuthException {
        T authModule;
        try {
            authModule = java.security.AccessController
            .doPrivileged(new PrivilegedExceptionAction<T>() {
                public T run() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, AuthException {
                    Class<? extends T> cl = (Class<? extends T>) ProviderLocator.loadClass(authModuleType.getClassName(), getClass(), Thread.currentThread().getContextClassLoader());
                    Constructor<? extends T> cnst = cl.getConstructor();
                    T authModule = cnst.newInstance();
                    Method m = cl.getMethod("initialize", MessagePolicy.class, MessagePolicy.class, CallbackHandler.class, Map.class);
                    MessagePolicy reqPolicy = newMessagePolicy(authModuleType.getRequestPolicy());
                    MessagePolicy respPolicy = newMessagePolicy(authModuleType.getResponsePolicy());
                    m.invoke(authModule, reqPolicy, respPolicy, callbackHandler, authModuleType.getOptions());
                    return authModule;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception inner = e.getException();
            if (inner instanceof InstantiationException) {
                throw (AuthException) new AuthException("AuthConfigFactory error:"
                                + inner.getCause().getMessage()).initCause(inner.getCause());
            } else {
                throw (AuthException) new AuthException("AuthConfigFactory error: " + inner).initCause(inner);
            }
        } catch (Exception e) {
            throw (AuthException) new AuthException("AuthConfigFactory error: " + e).initCause(e);
        }
        return authModule;
    }