Search in sources :

Example 1 with AuthenticationResponse

use of org.apache.openejb.client.AuthenticationResponse in project tomee by apache.

the class AuthRequestHandler method processResponse.

@Override
public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
    if (AuthenticationResponse.class.isInstance(response)) {
        final AuthenticationResponse res = (AuthenticationResponse) response;
        res.setMetaData(metaData);
        try {
            res.writeExternal(out);
        } catch (Exception e) {
            logger.fatal("Could not write AuthenticationResponse to output stream", e);
        }
    } else {
        logger.error("AuthRequestHandler cannot process an instance of: " + response.getClass().getName());
    }
}
Also used : AuthenticationResponse(org.apache.openejb.client.AuthenticationResponse)

Example 2 with AuthenticationResponse

use of org.apache.openejb.client.AuthenticationResponse in project tomee by apache.

the class AuthRequestHandler method processRequest.

@Override
public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
    final AuthenticationRequest req = new AuthenticationRequest();
    req.setMetaData(metaData);
    final AuthenticationResponse res = new AuthenticationResponse();
    res.setMetaData(metaData);
    try {
        req.readExternal(in);
        final String securityRealm = req.getRealm();
        final String username = req.getUsername();
        final String password = req.getCredentials();
        final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
        final Object token = securityService.login(securityRealm, username, password);
        final ClientMetaData client = new ClientMetaData();
        client.setMetaData(metaData);
        client.setClientIdentity(token);
        res.setIdentity(client);
        res.setResponseCode(ResponseCodes.AUTH_GRANTED);
    } catch (Throwable t) {
        res.setResponseCode(ResponseCodes.AUTH_DENIED);
        res.setDeniedCause(t);
    } finally {
        if (debug) {
            try {
                logger.debug("AUTH REQUEST: " + req + " -- RESPONSE: " + res);
            } catch (Exception e) {
            //Ignore
            }
        }
    }
    return res;
}
Also used : SecurityService(org.apache.openejb.spi.SecurityService) AuthenticationRequest(org.apache.openejb.client.AuthenticationRequest) AuthenticationResponse(org.apache.openejb.client.AuthenticationResponse) ClientMetaData(org.apache.openejb.client.ClientMetaData)

Aggregations

AuthenticationResponse (org.apache.openejb.client.AuthenticationResponse)2 AuthenticationRequest (org.apache.openejb.client.AuthenticationRequest)1 ClientMetaData (org.apache.openejb.client.ClientMetaData)1 SecurityService (org.apache.openejb.spi.SecurityService)1