Search in sources :

Example 1 with ClientAuthContext

use of javax.security.auth.message.config.ClientAuthContext in project Payara by payara.

the class ClientAuthConfigImpl method createAuthContext.

@Override
@SuppressWarnings("unchecked")
protected <M> M createAuthContext(String authContextID, Map<String, ?> properties) throws AuthException {
    if (!authContextHelper.isProtected(new ClientAuthModule[0], authContextID)) {
        return null;
    }
    ClientAuthContext context = new ClientAuthContext() {

        ClientAuthModule[] module = init();

        ClientAuthModule[] init() throws AuthException {
            ClientAuthModule[] clientModules;
            try {
                clientModules = authContextHelper.getModules(new ClientAuthModule[0], authContextID);
            } catch (AuthException ae) {
                logIfLevel(SEVERE, ae, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "unable to load client auth modules");
                throw ae;
            }
            MessagePolicy requestPolicy = policyDelegate.getRequestPolicy(authContextID, properties);
            MessagePolicy responsePolicy = policyDelegate.getResponsePolicy(authContextID, properties);
            boolean noModules = true;
            for (int i = 0; i < clientModules.length; i++) {
                if (clientModules[i] != null) {
                    if (isLoggable(FINE)) {
                        logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "initializing module");
                    }
                    noModules = false;
                    checkMessageTypes(clientModules[i].getSupportedMessageTypes());
                    clientModules[i].initialize(requestPolicy, responsePolicy, callbackHandler, authContextHelper.getInitProperties(i, properties));
                }
            }
            if (noModules) {
                logIfLevel(WARNING, null, "CLientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "contains no Auth Modules");
            }
            return clientModules;
        }

        @Override
        public AuthStatus validateResponse(MessageInfo arg0, Subject arg1, Subject arg2) throws AuthException {
            AuthStatus[] status = new AuthStatus[module.length];
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling vaidateResponse on module");
                }
                status[i] = module[i].validateResponse(arg0, arg1, arg2);
                if (authContextHelper.exitContext(validateResponseSuccessValues, i, status[i])) {
                    return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, i);
                }
            }
            return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, status.length - 1);
        }

        @Override
        public AuthStatus secureRequest(MessageInfo arg0, Subject arg1) throws AuthException {
            AuthStatus[] status = new AuthStatus[module.length];
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling secureResponse on module");
                }
                status[i] = module[i].secureRequest(arg0, arg1);
                if (authContextHelper.exitContext(secureResponseSuccessValues, i, status[i])) {
                    return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, i);
                }
            }
            return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, status.length - 1);
        }

        @Override
        public void cleanSubject(MessageInfo arg0, Subject arg1) throws AuthException {
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling cleanSubject on module");
                }
                module[i].cleanSubject(arg0, arg1);
            }
        }
    };
    return (M) context;
}
Also used : MessagePolicy(javax.security.auth.message.MessagePolicy) ClientAuthModule(javax.security.auth.message.module.ClientAuthModule) AuthStatus(javax.security.auth.message.AuthStatus) AuthException(javax.security.auth.message.AuthException) ClientAuthContext(javax.security.auth.message.config.ClientAuthContext) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo)

Aggregations

Subject (javax.security.auth.Subject)1 AuthException (javax.security.auth.message.AuthException)1 AuthStatus (javax.security.auth.message.AuthStatus)1 MessageInfo (javax.security.auth.message.MessageInfo)1 MessagePolicy (javax.security.auth.message.MessagePolicy)1 ClientAuthContext (javax.security.auth.message.config.ClientAuthContext)1 ClientAuthModule (javax.security.auth.message.module.ClientAuthModule)1