Example usage for javax.xml.ws.handler.soap SOAPMessageContext setScope

List of usage examples for javax.xml.ws.handler.soap SOAPMessageContext setScope

Introduction

In this page you can find the example usage for javax.xml.ws.handler.soap SOAPMessageContext setScope.

Prototype

public void setScope(String name, Scope scope);

Source Link

Document

Sets the scope of a property.

Usage

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleInboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (null == soapHeader) {
        return;/* w  w  w  .j av a  2  s .c  o  m*/
    }
    Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements();
    while (headerIterator.hasNext()) {
        SOAPHeaderElement soapHeaderElement = headerIterator.next();
        if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) {
            continue;
        }
        if (false == "Security".equals(soapHeaderElement.getLocalName())) {
            continue;
        }
        Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements();
        while (securityElementIterator.hasNext()) {
            SOAPElement securityElement = securityElementIterator.next();
            if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) {
                continue;
            }
            if (false == "Assertion".equals(securityElement.getLocalName())) {
                continue;
            }
            LOG.debug("putting SAML token on JAX-WS context");
            context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement);
            context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION);
        }
    }
}

From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    //for response message only, true for outbound messages, false for inbound
    if (!isRequest) {
        try {/*from   w  w w  . j ava  2s. co  m*/

            WebServiceServerConfiguration configuration = getWebServiceServerConfiguration(
                    ((com.sun.xml.ws.api.server.WSEndpoint) context.get("com.sun.xml.ws.api.server.WSEndpoint"))
                            .getImplementationClass().getName());

            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnv.getHeader();

            if (!configuration.isActive()) {
                generateSOAPErrorMessage(soapMsg, "Sorry webservice is disabled at application level!");
            }

            if (configuration.isAuthenticatioNeeded()) {

                if (configuration.isUsingWSSecurity()) {
                    if (soapHeader == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "No header in message, unabled to validate security credentials");
                    }

                    String username = null;
                    String password = null;
                    String nonce = null;
                    String created = null;

                    Iterator<SOAPElement> childElements = soapHeader.getChildElements(QNAME_WSSE_SECURITY);
                    if (childElements.hasNext()) {
                        SOAPElement securityElement = childElements.next();
                        Iterator<SOAPElement> usernameTokens = securityElement
                                .getChildElements(QNAME_WSSE_USERNAME_TOKEN);
                        if (usernameTokens.hasNext()) {
                            SOAPElement usernameToken = usernameTokens.next();
                            username = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_USERNAME)
                                    .next()).getValue();
                            password = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_PASSWORD)
                                    .next()).getValue();
                            nonce = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_NONCE).next())
                                    .getValue();
                            created = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_CREATED).next())
                                    .getValue();
                        }
                    }
                    if (username == null || password == null || nonce == null || created == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "Missing information, unabled to validate security credentials");
                    }

                    SecurityHeader securityHeader = new SecurityHeader(configuration, username, password, nonce,
                            created);
                    if (!securityHeader.isValid()) {
                        generateSOAPErrorMessage(soapMsg, "Invalid credentials");
                    } else {
                        context.put(BennuWebService.SECURITY_HEADER, securityHeader);
                        context.setScope(BennuWebService.SECURITY_HEADER, Scope.APPLICATION);
                    }
                } else {
                    com.sun.xml.ws.transport.Headers httpHeader = (Headers) context
                            .get(MessageContext.HTTP_REQUEST_HEADERS);
                    String username = null;
                    String password = null;
                    List<String> list = httpHeader.get("authorization");
                    if (list != null) {
                        for (String value : list) {
                            if (value.startsWith("Basic")) {
                                String[] split = value.split(" ");
                                try {
                                    String decoded = new String(Base64.decodeBase64(split[1]), "UTF-8");
                                    String[] split2 = decoded.split(":");
                                    if (split2.length == 2) {
                                        username = split2[0];
                                        password = split2[1];
                                    }
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }

                    if (username == null || password == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "Missing information, unabled to validate security credentials");
                    }

                    if (!configuration.validate(username, password)) {
                        generateSOAPErrorMessage(soapMsg, "Invalid credentials");
                    }
                }
            }

        } catch (SOAPException e) {
            System.err.println(e);
        }
    }

    //continue other handler chain
    return true;
}

From source file:org.apache.axis2.jaxws.context.utils.ContextUtils.java

private static void setProperty(SOAPMessageContext context, String name, Object value, boolean logMessage) {
    context.put(name, value);//  w  w w. j a v a  2  s.c o  m
    context.setScope(name, Scope.APPLICATION);
    if (logMessage && log.isDebugEnabled()) {
        log.debug(name + " :" + value);
    }
}

From source file:org.apache.juddi.xlt.util.LoggingHandler.java

private void registerMessage(SOAPMessageContext context) {
    RequestData reqData = new RequestData(getOperationName(context));
    reqData.setBytesSent(0);/*from  www  . j a  v a2s  .c  om*/

    context.put(XLT_REQUEST_DATA, reqData);
    context.setScope(XLT_REQUEST_DATA, MessageContext.Scope.HANDLER);
}

From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAuthHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    boolean res = super.handleMessage(context);

    HttpServletRequest request = (HttpServletRequest) context.get(MessageContext.SERVLET_REQUEST);
    request.setAttribute(CmisWebServicesServlet.CMIS_VERSION, CmisVersion.CMIS_1_1);

    @SuppressWarnings("unchecked")
    Map<String, String> callContextMap = (Map<String, String>) context.get(AbstractService.CALL_CONTEXT_MAP);
    if (callContextMap != null) {
        // login to Nuxeo
        String username = callContextMap.get(CallContext.USERNAME);
        String password = callContextMap.get(CallContext.PASSWORD);
        try {/*from   w w  w  .  j  a  v  a2  s.  c o  m*/
            LoginContext loginContext = getLoginProvider().login(username, password);
            // store in message context, for later logout
            context.put(NUXEO_LOGIN_CONTEXT, loginContext);
            context.setScope(NUXEO_LOGIN_CONTEXT, Scope.APPLICATION);
        } catch (LoginException e) {
            throw new RuntimeException("Login failed for user '" + username + "'", e);
        }
    }
    return res;
}