Search in sources :

Example 1 with PacketMapMessageInfo

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

the class ClientSecurityTube method preDestroy.

@Override
public void preDestroy() {
    // create a dummy request packet
    try {
        Packet request = new Packet();
        PacketMessageInfo locInfo = new PacketMapMessageInfo(request, new Packet());
        Subject subj = getClientSubject(request);
        ClientAuthContext locCAC = helper.getClientAuthContext(locInfo, subj);
        if (locCAC != null && WSIT_CLIENT_AUTH_CONTEXT.equals(locCAC.getClass().getName())) {
            locCAC.cleanSubject(locInfo, subj);
        }
    } catch (Exception ex) {
    // ignore exceptions
    }
    helper.disable();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) 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)

Example 2 with PacketMapMessageInfo

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

the class ClientSecurityTube method startSecureConversation.

@Override
public JAXBElement startSecureConversation(Packet packet) throws WSSecureConversationException {
    PacketMessageInfo locInfo = new PacketMapMessageInfo(packet, new Packet());
    JAXBElement token = null;
    try {
        // gets the subject from the packet (puts one there if not found)
        Subject locClientSubject = getClientSubject(packet);
        // put MessageInfo in properties map, since MessageInfo
        // is not passed to getAuthContext, key idicates function
        HashMap<String, Object> map = new HashMap<>();
        map.put(SECURITY_TOKEN, locInfo);
        helper.getSessionToken(map, locInfo, locClientSubject);
        // helper returns token in map of msgInfo, using same key
        Object o = locInfo.getMap().get(SECURITY_TOKEN);
        if (o != null && o instanceof JAXBElement) {
            token = (JAXBElement) o;
        }
    } catch (Exception e) {
        if (e instanceof WSSecureConversationException) {
            throw (WSSecureConversationException) e;
        } else {
            throw new WSSecureConversationException("Secure Conversation failure: ", e);
        }
    }
    return token;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) HashMap(java.util.HashMap) WSSecureConversationException(com.sun.xml.ws.security.secconv.WSSecureConversationException) JAXBElement(javax.xml.bind.JAXBElement) 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)

Example 3 with PacketMapMessageInfo

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

the class CommonServerSecurityTube method processRequest.

@Override
public NextAction processRequest(Packet request) {
    try {
        if (isHttpBinding) {
            return doInvoke(super.next, request);
        }
        AuthStatus status = AuthStatus.SUCCESS;
        info = new PacketMapMessageInfo(request, new Packet());
        // XXX at this time, we expect the server subject to be null
        serverSubject = (Subject) request.invocationProperties.get(PipeConstants.SERVER_SUBJECT);
        // could change the request packet
        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
            Packet ret = helper.getFaultResponse(info.getRequestPacket(), info.getResponsePacket(), wse);
            return doReturnWith(ret);
        } 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);
                return doReturnWith(response);
            }
            if (authorized) {
                // only do doAdPriv if SecurityManager is in effect
                if (System.getSecurityManager() == null) {
                    try {
                        // proceed to invoke the endpoint
                        return doInvoke(super.next, validatedRequest);
                    } catch (Exception e) {
                        _logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, e);
                        response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), e);
                        return doReturnWith(response);
                    }
                } else {
                    try {
                        final Tube next = super.next;
                        NextAction action = (NextAction) Subject.doAsPrivileged(clientSubject, new PrivilegedExceptionAction() {

                            @Override
                            public Object run() throws Exception {
                                // proceed to invoke the endpoint
                                return doInvoke(next, validatedRequest);
                            }
                        }, null);
                        return action;
                    } catch (PrivilegedActionException pae) {
                        Throwable cause = pae.getCause();
                        _logger.log(Level.SEVERE, LogUtils.NEXT_PIPE, cause);
                        response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), cause);
                        return doReturnWith(response);
                    }
                }
            } else {
                // if not authorized
                // not authorized, construct fault and proceded
                response = helper.getFaultResponse(validatedRequest, info.getResponsePacket(), new Exception("Client Not Authorized"));
                return doReturnWith(response);
            }
        } 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 doReturnWith(response);
        }
    } catch (Throwable t) {
        if (!(t instanceof WebServiceException)) {
            t = new WebServiceException(t);
        }
        return doThrow(t);
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) Tube(com.sun.xml.ws.api.pipe.Tube) WebServiceException(javax.xml.ws.WebServiceException) AuthStatus(javax.security.auth.message.AuthStatus) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) NextAction(com.sun.xml.ws.api.pipe.NextAction) Subject(javax.security.auth.Subject) PrivilegedActionException(java.security.PrivilegedActionException) AuthException(javax.security.auth.message.AuthException) WebServiceException(javax.xml.ws.WebServiceException)

Example 4 with PacketMapMessageInfo

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

the class ClientSecurityPipe method startSecureConversation.

@Override
public JAXBElement startSecureConversation(Packet packet) throws WSSecureConversationException {
    PacketMessageInfo info = new PacketMapMessageInfo(packet, new Packet());
    JAXBElement token = null;
    try {
        // gets the subject from the packet (puts one there if not found)
        Subject clientSubject = getClientSubject(packet);
        // put MessageInfo in properties map, since MessageInfo
        // is not passed to getAuthContext, key indicates function
        HashMap<String, Object> map = new HashMap<>();
        map.put(PipeConstants.SECURITY_TOKEN, info);
        helper.getSessionToken(map, info, clientSubject);
        // helper returns token in map of msgInfo, using same key
        Object o = info.getMap().get(PipeConstants.SECURITY_TOKEN);
        if (o != null && o instanceof JAXBElement) {
            token = (JAXBElement) o;
        }
    } catch (Exception e) {
        if (e instanceof WSSecureConversationException) {
            throw (WSSecureConversationException) e;
        } else {
            throw new WSSecureConversationException("Secure Conversation failure: ", e);
        }
    }
    return token;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) HashMap(java.util.HashMap) WSSecureConversationException(com.sun.xml.ws.security.secconv.WSSecureConversationException) JAXBElement(javax.xml.bind.JAXBElement) 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)

Example 5 with PacketMapMessageInfo

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

the class ClientSecurityPipe method preDestroy.

@Override
public void preDestroy() {
    // create a dummy request packet
    try {
        Packet request = new Packet();
        PacketMessageInfo info = new PacketMapMessageInfo(request, new Packet());
        Subject subj = getClientSubject(request);
        ClientAuthContext cAC = helper.getClientAuthContext(info, subj);
        if (cAC != null && WSIT_CLIENT_AUTH_CONTEXT.equals(cAC.getClass().getName())) {
            cAC.cleanSubject(info, subj);
        }
    } catch (Exception ex) {
    // ignore exceptions
    }
    helper.disable();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) PacketMapMessageInfo(com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo) 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

PacketMapMessageInfo (com.sun.enterprise.security.jauth.jaspic.provider.PacketMapMessageInfo)9 Packet (com.sun.xml.ws.api.message.Packet)9 Subject (javax.security.auth.Subject)9 WebServiceException (javax.xml.ws.WebServiceException)9 PacketMessageInfo (com.sun.enterprise.security.jauth.jaspic.provider.PacketMessageInfo)7 WSSecureConversationException (com.sun.xml.ws.security.secconv.WSSecureConversationException)6 AuthStatus (javax.security.auth.message.AuthStatus)4 PrivilegedActionException (java.security.PrivilegedActionException)3 AuthException (javax.security.auth.message.AuthException)3 ClientAuthContext (javax.security.auth.message.config.ClientAuthContext)3 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 HashMap (java.util.HashMap)2 ServerAuthContext (javax.security.auth.message.config.ServerAuthContext)2 JAXBElement (javax.xml.bind.JAXBElement)2 NextAction (com.sun.xml.ws.api.pipe.NextAction)1 Tube (com.sun.xml.ws.api.pipe.Tube)1