Search in sources :

Example 6 with PacketMessageInfo

use of com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo in project Payara by payara.

the class CommonServerSecurityPipe method processRequest.

private Packet processRequest(Packet request) throws Exception {
    AuthStatus status = AuthStatus.SUCCESS;
    PacketMessageInfo info = new PacketMapMessageInfo(request, new Packet());
    // XXX at this time, we expect the server subject to be null
    Subject serverSubject = (Subject) request.invocationProperties.get(PipeConstants.SERVER_SUBJECT);
    // could change the request packet
    ServerAuthContext sAC = helper.getServerAuthContext(info, serverSubject);
    Subject clientSubject = getClientSubject(request);
    final Packet validatedRequest;
    try {
        if (sAC != null) {
            // client subject must not be null
            // and when return status is SUCCESS, module
            // must have called handler.handle(CallerPrincipalCallback)
            status = sAC.validateRequest(info, clientSubject, serverSubject);
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_VALIDATION, e);
        WebServiceException wse = new WebServiceException(localStrings.getLocalString("enterprise.webservice.cantValidateRequest", "Cannot validate request for {0}", new Object[] { helper.getModelName() }), e);
        // set status for audit
        status = AuthStatus.SEND_FAILURE;
        // if unable to determine if two-way will return empty response
        return helper.getFaultResponse(info.getRequestPacket(), info.getResponsePacket(), wse);
    } finally {
        validatedRequest = info.getRequestPacket();
        helper.auditInvocation(validatedRequest, status);
    }
    Packet response = null;
    if (status == AuthStatus.SUCCESS) {
        boolean authorized = false;
        try {
            helper.authorize(validatedRequest);
            authorized = true;
        } catch (Exception e) {
            // not authorized, construct fault and proceded
            response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
        }
        if (authorized) {
            // only do doAdPriv if SecurityManager is in effect
            if (System.getSecurityManager() == null) {
                try {
                    // proceed to invoke the endpoint
                    response = next.process(validatedRequest);
                } catch (Exception e) {
                    _logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, e);
                    response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
                }
            } else {
                try {
                    response = (Packet) Subject.doAsPrivileged(clientSubject, new PrivilegedExceptionAction() {

                        @Override
                        public Object run() throws Exception {
                            // proceed to invoke the endpoint
                            return next.process(validatedRequest);
                        }
                    }, null);
                } catch (PrivilegedActionException pae) {
                    Throwable cause = pae.getCause();
                    _logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, cause);
                    response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), cause);
                }
            }
        }
        // pipes are not supposed to return a null response packet
        if (response == null) {
            WebServiceException wse = new WebServiceException(localStrings.getLocalString("enterprise.webservice.nullResponsePacket", "Invocation of Service {0} returned null response packet", new Object[] { helper.getModelName() }));
            response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), wse);
            _logger.log(Level.SEVERE, LogUtils.EXCEPTION_THROWN, wse);
        }
        // secure response, including if it is a fault
        if (sAC != null && response.getMessage() != null) {
            info.setResponsePacket(response);
            response = processResponse(info, sAC, serverSubject);
        }
    } else {
        // validateRequest did not return success
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "ws.status_validate_request", status);
        }
        // even for one-way mep, may return response with non-empty message
        response = info.getResponsePacket();
    }
    return response;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) WebServiceException(javax.xml.ws.WebServiceException) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException) ServerAuthContext(javax.security.auth.message.config.ServerAuthContext) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) AuthStatus(javax.security.auth.message.AuthStatus) PacketMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo)

Example 7 with PacketMessageInfo

use of com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo in project Payara by payara.

the class CommonServerSecurityPipe method preDestroy.

/**
 * This method is called once in server side and at most one in client side.
 */
@Override
public void preDestroy() {
    helper.disable();
    try {
        Packet request = new Packet();
        PacketMessageInfo info = new PacketMapMessageInfo(request, new Packet());
        Subject subj = new Subject();
        ServerAuthContext sAC = helper.getServerAuthContext(info, subj);
        if (sAC != null && WSIT_SERVER_AUTH_CONTEXT.equals(sAC.getClass().getName())) {
            sAC.cleanSubject(info, subj);
        }
    } catch (Exception ex) {
    // ignore exceptions
    }
    /**
     * Fix for bug 3932/4052
     */
    next.preDestroy();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException) PacketMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo) ServerAuthContext(javax.security.auth.message.config.ServerAuthContext)

Example 8 with PacketMessageInfo

use of com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo in project Payara by payara.

the class ClientSecurityPipe method process.

@Override
public Packet process(Packet request) {
    /*
         * XXX should there be code like the following? if(isHttpBinding) { return next.process(request); }
         */
    PacketMessageInfo info = new PacketMapMessageInfo(request, new Packet());
    info.getMap().put(javax.xml.ws.Endpoint.WSDL_SERVICE, helper.getProperty(PipeConstants.WSDL_SERVICE));
    AuthStatus status = AuthStatus.SEND_SUCCESS;
    Subject clientSubject = getClientSubject(request);
    ClientAuthContext cAC = null;
    try {
        cAC = helper.getClientAuthContext(info, clientSubject);
        if (cAC != null) {
            // proceed to process message sescurity
            status = cAC.secureRequest(info, clientSubject);
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, LogUtils.ERROR_REQUEST_SECURING, e);
        throw new WebServiceException(localStrings.getLocalString("enterprise.webservice.cantSecureRequst", "Cannot secure request for {0}", new Object[] { helper.getModelName() }), e);
    }
    Packet response;
    if (status == AuthStatus.FAILURE) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "ws.status_secure_request", status);
        }
        response = info.getResponsePacket();
    } else {
        response = processSecureRequest(info, cAC, clientSubject);
    }
    // may return a security fault even if the MEP was one-way
    return response;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) WebServiceException(javax.xml.ws.WebServiceException) AuthStatus(javax.security.auth.message.AuthStatus) ClientAuthContext(javax.security.auth.message.config.ClientAuthContext) Subject(javax.security.auth.Subject) WSSecureConversationException(com.sun.xml.ws.security.secconv.WSSecureConversationException) WebServiceException(javax.xml.ws.WebServiceException) PacketMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo)

Aggregations

PacketMessageInfo (com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo)8 Packet (com.sun.xml.ws.api.message.Packet)8 PacketMapMessageInfo (com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo)7 Subject (javax.security.auth.Subject)7 WebServiceException (javax.xml.ws.WebServiceException)7 WSSecureConversationException (com.sun.xml.ws.security.secconv.WSSecureConversationException)5 ClientAuthContext (javax.security.auth.message.config.ClientAuthContext)3 PrivilegedActionException (java.security.PrivilegedActionException)2 HashMap (java.util.HashMap)2 AuthException (javax.security.auth.message.AuthException)2 AuthStatus (javax.security.auth.message.AuthStatus)2 ServerAuthContext (javax.security.auth.message.config.ServerAuthContext)2 JAXBElement (javax.xml.bind.JAXBElement)2 Message (com.sun.xml.ws.api.message.Message)1 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 QName (javax.xml.namespace.QName)1 SOAPMessage (javax.xml.soap.SOAPMessage)1