Package org.picketlink.identity.federation.core.wstrust.wrappers

Examples of org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenResponse


        if (contextSecurityToken == null)
            throw new WSTrustException(logger.nullValueError("Security Token from context"));

        requestedSecurityToken.add(contextSecurityToken.getTokenValue());

        RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
        if (request.getContext() != null)
            response.setContext(request.getContext());

        response.setTokenType(request.getTokenType());
        response.setLifetime(request.getLifetime());
        response.setAppliesTo(appliesTo);
        response.setKeySize(keySize);
        response.setKeyType(keyType);
        response.setRequestedSecurityToken(requestedSecurityToken);

        if (requestedProofToken != null)
            response.setRequestedProofToken(requestedProofToken);
        if (serverEntropy != null)
            response.setEntropy(serverEntropy);

        // set the attached and unattached references.
        if (requestContext.getAttachedReference() != null)
            response.setRequestedAttachedReference(requestContext.getAttachedReference());
        if (requestContext.getUnattachedReference() != null)
            response.setRequestedUnattachedReference(requestContext.getUnattachedReference());

        return response;
    }
View Full Code Here


        SecurityToken contextSecurityToken = context.getSecurityToken();
        if (contextSecurityToken == null)
            throw new WSTrustException(logger.nullValueError("Security Token from context"));
        requestedSecurityToken.add(contextSecurityToken.getTokenValue());

        RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
        if (request.getContext() != null)
            response.setContext(request.getContext());
        response.setTokenType(request.getTokenType());
        response.setLifetime(request.getLifetime());
        response.setRequestedSecurityToken(requestedSecurityToken);
        if (context.getAttachedReference() != null)
            response.setRequestedAttachedReference(context.getAttachedReference());
        if (context.getUnattachedReference() != null)
            response.setRequestedUnattachedReference(context.getUnattachedReference());
        return response;
    }
View Full Code Here

            }
            status = context.getStatus();
        }

        // construct and return the response.
        RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
        if (request.getContext() != null)
            response.setContext(request.getContext());
        response.setTokenType(request.getTokenType());
        response.setStatus(status);

        return response;
    }
View Full Code Here

        } catch (ProcessingException e) {
            throw logger.stsError(e);
        }

        // if no exception has been raised, the token has been successfully canceled.
        RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
        if (request.getContext() != null)
            response.setContext(request.getContext());
        response.setRequestedTokenCancelled(new RequestedTokenCancelledType());
        return response;
    }
View Full Code Here

            String tag = StaxParserUtil.getStartElementName(peekedElement);

            if (WSTrustConstants.RSTR.equalsIgnoreCase(tag)) {
                WSTRequestSecurityTokenResponseParser rstrParser = new WSTRequestSecurityTokenResponseParser();
                RequestSecurityTokenResponse rstr = (RequestSecurityTokenResponse) rstrParser.parse(xmlEventReader);
                requestCollection.addRequestSecurityTokenResponse(rstr);
            }
        }
        return requestCollection;
    }
View Full Code Here

     * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
     */
    public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
        StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);

        RequestSecurityTokenResponse responseToken = new RequestSecurityTokenResponse();

        QName contextQName = new QName("", WSTrustConstants.RST_CONTEXT);
        Attribute contextAttribute = startElement.getAttributeByName(contextQName);
        String contextValue = StaxParserUtil.getAttributeValue(contextAttribute);
        responseToken.setContext(contextValue);

        while (xmlEventReader.hasNext()) {
            XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
            if (xmlEvent == null)
                break;
            if (xmlEvent instanceof EndElement) {
                xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
                EndElement endElement = (EndElement) xmlEvent;
                String endElementTag = StaxParserUtil.getEndElementName(endElement);
                if (endElementTag.equals(WSTrustConstants.RSTR))
                    break;
                else
                    throw logger.parserUnknownEndElement(endElementTag);
            }

            try {
                StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
                if (subEvent == null)
                    break;

                String tag = StaxParserUtil.getStartElementName(subEvent);
                if (tag.equals(WSTrustConstants.REQUEST_TYPE)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw logger.parserExpectedTextValue("request type");

                    String value = StaxParserUtil.getElementText(xmlEventReader);
                    responseToken.setRequestType(new URI(value));
                } else if (tag.equals(WSTrustConstants.LIFETIME)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    StaxParserUtil.validate(subEvent, WSTrustConstants.LIFETIME);

                    LifetimeType lifeTime = new LifetimeType();
                    // Get the Created
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    String subTag = StaxParserUtil.getStartElementName(subEvent);
                    if (subTag.equals(WSTrustConstants.CREATED)) {
                        AttributedDateTime created = new AttributedDateTime();
                        created.setValue(StaxParserUtil.getElementText(xmlEventReader));
                        lifeTime.setCreated(created);
                    }
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    subTag = StaxParserUtil.getStartElementName(subEvent);

                    if (subTag.equals(WSTrustConstants.EXPIRES)) {
                        AttributedDateTime expires = new AttributedDateTime();
                        expires.setValue(StaxParserUtil.getElementText(xmlEventReader));
                        lifeTime.setExpires(expires);
                    } else
                        throw logger.parserUnknownTag(subTag, subEvent.getLocation());

                    responseToken.setLifetime(new Lifetime(lifeTime));
                    EndElement lifeTimeElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(lifeTimeElement, WSTrustConstants.LIFETIME);
                } else if (tag.equals(WSTrustConstants.TOKEN_TYPE)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw logger.parserExpectedTextValue("token type");

                    String value = StaxParserUtil.getElementText(xmlEventReader);
                    responseToken.setTokenType(new URI(value));
                } else if (tag.equals(WSTrustConstants.ON_BEHALF_OF)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    WSTrustOnBehalfOfParser wstOnBehalfOfParser = new WSTrustOnBehalfOfParser();
                    OnBehalfOfType onBehalfOf = (OnBehalfOfType) wstOnBehalfOfParser.parse(xmlEventReader);
                    responseToken.setOnBehalfOf(onBehalfOf);
                    EndElement onBehalfOfEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(onBehalfOfEndElement, WSTrustConstants.ON_BEHALF_OF);
                } else if (tag.equals(WSTrustConstants.KEY_TYPE)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw logger.parserExpectedTextValue("key type");

                    String keyType = StaxParserUtil.getElementText(xmlEventReader);
                    try {
                        URI keyTypeURI = new URI(keyType);
                        responseToken.setKeyType(keyTypeURI);
                    } catch (URISyntaxException e) {
                        throw new ParsingException(e);
                    }
                } else if (tag.equals(WSTrustConstants.KEY_SIZE)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw logger.parserExpectedTextValue("key size");

                    String keySize = StaxParserUtil.getElementText(xmlEventReader);
                    try {
                        responseToken.setKeySize(Long.parseLong(keySize));
                    } catch (NumberFormatException e) {
                        throw logger.parserException(e);
                    }
                } else if (tag.equals(WSTrustConstants.ENTROPY)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    EntropyType entropy = new EntropyType();
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    if (StaxParserUtil.matches(subEvent, WSTrustConstants.BINARY_SECRET)) {
                        BinarySecretType binarySecret = new BinarySecretType();
                        Attribute typeAttribute = subEvent.getAttributeByName(new QName("", "Type"));
                        if (typeAttribute != null) {
                            binarySecret.setType(StaxParserUtil.getAttributeValue(typeAttribute));
                        }

                        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                            throw logger.parserExpectedTextValue("binary secret value");

                        binarySecret.setValue(StaxParserUtil.getElementText(xmlEventReader).getBytes());
                        entropy.addAny(binarySecret);
                    }
                    responseToken.setEntropy(entropy);
                    EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(endElement, WSTrustConstants.ENTROPY);
                } else if (tag.equals(WSTrustConstants.USE_KEY)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    UseKeyType useKeyType = new UseKeyType();
                    StaxParserUtil.validate(subEvent, WSTrustConstants.USE_KEY);

                    // We peek at the next start element as the stax source has to be in the START_ELEMENT mode
                    subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
                    if (StaxParserUtil.matches(subEvent, X509CERTIFICATE)) {
                        Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
                        // Element domElement = getX509CertificateAsDomElement( subEvent, xmlEventReader );

                        useKeyType.add(domElement);
                        responseToken.setUseKey(useKeyType);
                    } else if (StaxParserUtil.matches(subEvent, KEYVALUE)) {
                        Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
                        useKeyType.add(domElement);
                        responseToken.setUseKey(useKeyType);
                    } else
                        throw logger.parserUnknownStartElement(StaxParserUtil.getStartElementName(subEvent), subEvent.getLocation());
                } else if (tag.equals(WSTrustConstants.REQUESTED_TOKEN_CANCELLED)) {
                    StaxParserUtil.getNextEndElement(xmlEventReader);
                    responseToken.setRequestedTokenCancelled(new RequestedTokenCancelledType());
                } else if (tag.equals(WSTrustConstants.REQUESTED_PROOF_TOKEN)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    RequestedProofTokenType requestedProofToken = new RequestedProofTokenType();
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    if (StaxParserUtil.matches(subEvent, WSTrustConstants.BINARY_SECRET)) {
                        BinarySecretType binarySecret = new BinarySecretType();
                        Attribute typeAttribute = subEvent.getAttributeByName(new QName("", "Type"));
                        binarySecret.setType(StaxParserUtil.getAttributeValue(typeAttribute));

                        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                            throw logger.parserExpectedTextValue("binary secret value");

                        binarySecret.setValue(StaxParserUtil.getElementText(xmlEventReader).getBytes());
                        requestedProofToken.add(binarySecret);
                    } else if (StaxParserUtil.matches(subEvent, WSTrustConstants.COMPUTED_KEY)) {
                        ComputedKeyType computedKey = new ComputedKeyType();
                        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                            throw logger.parserExpectedTextValue("computed key algorithm");
                        computedKey.setAlgorithm(StaxParserUtil.getElementText(xmlEventReader));
                        requestedProofToken.add(computedKey);
                    }
                    responseToken.setRequestedProofToken(requestedProofToken);
                    EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(endElement, WSTrustConstants.REQUESTED_PROOF_TOKEN);
                } else if (tag.equals(WSTrustConstants.REQUESTED_TOKEN)) {
                    responseToken.setRequestedSecurityToken(parseRequestedSecurityTokenType(xmlEventReader));
                } else if (tag.equals(WSTrustConstants.REQUESTED_ATTACHED_REFERENCE)) {
                    responseToken.setRequestedAttachedReference(parseRequestedReference(xmlEventReader, WSTrustConstants.REQUESTED_ATTACHED_REFERENCE));
                } else if (tag.equals(WSTrustConstants.REQUESTED_UNATTACHED_REFERENCE)) {
                    responseToken.setRequestedUnattachedReference(parseRequestedReference(xmlEventReader, WSTrustConstants.REQUESTED_UNATTACHED_REFERENCE));
                } else if (tag.equals(WSTrustConstants.STATUS)) {
                    responseToken.setStatus(this.parseStatusType(xmlEventReader));
                }
                else if (tag.equals(WSTrustConstants.RENEWING)) {
                    responseToken.setRenewing(WSTrustUtil.parseRenewingType(xmlEventReader));
                } else {
                    QName qname = subEvent.getName();

                    logger.trace("Looking for parser for element: " + qname);
                   
                    ParserNamespaceSupport parser = ParserController.get(qname);
                    if (parser == null)
                        throw logger.parserUnknownTag(qname.getLocalPart(), subEvent.getLocation());

                    Object parsedObject = parser.parse(xmlEventReader);
                    if (parsedObject instanceof AppliesTo) {
                        responseToken.setAppliesTo((AppliesTo) parsedObject);
                    }
                }
            } catch (URISyntaxException e) {
                throw logger.parserException(e);
            }
View Full Code Here

       
        try {
            InputStream stream = DocumentUtil.getNodeAsStream(DocumentUtil.getNodeFromSource(response));
            RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
                    .parse(stream);
            RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);

            StatusType status = tokenResponse.getStatus();
            if (status != null) {
                String code = status.getCode();
                return WSTrustConstants.STATUS_CODE_VALID.equals(code);
            }
            return false;
View Full Code Here

        // get the WS-Trust response and check for presence of the RequestTokenCanceled element.
        try {
            InputStream stream = DocumentUtil.getNodeAsStream(DocumentUtil.getNodeFromSource(response));
            RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
                    .parse(stream);
            RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);
            if (tokenResponse.getRequestedTokenCancelled() != null)
                return true;
            return false;
        } catch (Exception e) {
            throw new WSTrustException(logger.parserError(e));
        }
View Full Code Here

        assertNotNull(is);

        WSTrustParser parser = new WSTrustParser();
        RequestSecurityToken token = (RequestSecurityToken) parser.parse(is);

        RequestSecurityTokenResponse response = handler.issue(token, new Principal() {
            @Override
            public String getName() {
                return "testuser";
            }
        });
View Full Code Here

        // validate the response contents.
        assertNotNull("Unexpected null response", baseResponse);
        assertTrue("Unexpected response type", baseResponse instanceof RequestSecurityTokenResponseCollection);
        collection = (RequestSecurityTokenResponseCollection) baseResponse;
        assertEquals("Unexpected number of responses", 1, collection.getRequestSecurityTokenResponses().size());
        RequestSecurityTokenResponse response = collection.getRequestSecurityTokenResponses().get(0);
        assertEquals("Unexpected response context", "cancelcontext", response.getContext());
        assertNotNull("Cancel response should contain a RequestedTokenCancelled element", response.getRequestedTokenCancelled());

        // try to validate the canceled assertion.
        request = this.createRequest("validatecontext", WSTrustConstants.VALIDATE_REQUEST, null, null);
        ValidateTargetType validateTarget = new ValidateTargetType();
        validateTarget.add(assertion);
        request.setValidateTarget(validateTarget);

        // the response should contain a status indicating that the token is not valid.
        responseMessage = this.tokenService.invoke(this.createSourceFromRequest(request));
        collection = (RequestSecurityTokenResponseCollection) parser.parse(DocumentUtil.getSourceAsStream(responseMessage));
        assertEquals("Unexpected number of responses", 1, collection.getRequestSecurityTokenResponses().size());
        response = collection.getRequestSecurityTokenResponses().get(0);
        assertEquals("Unexpected response context", "validatecontext", response.getContext());
        assertEquals("Unexpected token type", WSTrustConstants.STATUS_TYPE, response.getTokenType().toString());
        StatusType status = response.getStatus();
        assertNotNull("Unexpected null status", status);
        assertEquals("Unexpected status code", WSTrustConstants.STATUS_CODE_INVALID, status.getCode());
        assertEquals("Unexpected status reason",
                "Validation failure: assertion with id " + assertion.getAttribute("AssertionID") + " has been canceled",
                status.getReason());
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.