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

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


      new SecurityInfo("UserB", "PassB"));
   
    Element assertion = null;
    try
    {
      RequestSecurityToken request = new RequestSecurityToken();
      request.setTokenType(URI.create(SAMLUtil.SAML2_TOKEN_TYPE));
      AttributedString as = new AttributedString();
      as.setValue("UserA");
      as.setId("UserA");
      UsernameTokenType utt = new UsernameTokenType();
      utt.setUsername(as);
      utt.setId("UserA");
      OnBehalfOfType obot = new OnBehalfOfType();
      obot.add(utt);
      request.setOnBehalfOf(obot);
      assertion = client.issueToken(request);
    }
    catch (WSTrustException wse)
    {
      log.error("Unable to issue assertion: ", wse);
View Full Code Here


     * @return
     * @throws WSTrustException
     */
    public boolean validateToken(Element token) throws WSTrustException {
        validateDispatch();
        RequestSecurityToken request = new RequestSecurityToken();
        request.setContext("context");

        request.setTokenType(URI.create(WSTrustConstants.STATUS_TYPE));
        request.setRequestType(URI.create(WSTrustConstants.VALIDATE_REQUEST));
        ValidateTargetType validateTarget = new ValidateTargetType();
        validateTarget.add(token);
        request.setValidateTarget(validateTarget);

        DOMSource requestSource = this.createSourceFromRequest(request);

        Source response = dispatchLocal.get().invoke(requestSource);
       
View Full Code Here

     * @throws WSTrustException if an error occurs while processing the cancel request.
     */
    public boolean cancelToken(Element securityToken) throws WSTrustException {
        validateDispatch();
        // create a WS-Trust cancel request containing the specified token.
        RequestSecurityToken request = new RequestSecurityToken();
        request.setRequestType(URI.create(WSTrustConstants.CANCEL_REQUEST));
        CancelTargetType cancelTarget = new CancelTargetType();
        cancelTarget.add(securityToken);
        request.setCancelTarget(cancelTarget);
        request.setContext("context");

        DOMSource requestSource = this.createSourceFromRequest(request);
        Source response = dispatchLocal.get().invoke(requestSource);
        // get the WS-Trust response and check for presence of the RequestTokenCanceled element.
        try {
View Full Code Here

            String tag = StaxParserUtil.getStartElementName(peekedElement);

            if (WSTrustConstants.RST.equalsIgnoreCase(tag)) {
                WSTRequestSecurityTokenParser rstParser = new WSTRequestSecurityTokenParser();
                RequestSecurityToken rst = (RequestSecurityToken) rstParser.parse(xmlEventReader);
                requestCollection.addRequestSecurityToken(rst);
            }
        }
        return requestCollection;
    }
View Full Code Here

     * @return
     * @throws WSTrustException
     */
    public Element issueToken(String tokenType) throws WSTrustException {
        // create a custom token request message.
        RequestSecurityToken request = new RequestSecurityToken();
        setTokenType(tokenType, request);

        if (wsaIssuerAddress != null) {
            request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress));
        }
        if (wspAppliesTo != null) {
            request.setAppliesTo(WSTrustUtil.createAppliesTo(wspAppliesTo));
        }
        // send the token request to JBoss STS and get the response.
        return issueToken(request);
    }
View Full Code Here

     *        which is an optional element so it may be null.
     * @return Element - The Security Token Element which will be of the TokenType configured for the endpointURI passed in.
     * @throws WSTrustException
     */
    public Element issueTokenForEndpoint(String endpointURI) throws WSTrustException {
        RequestSecurityToken request = new RequestSecurityToken();
        if (wsaIssuerAddress != null) {
            request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress));
        }
        setAppliesTo(endpointURI, request);
        return issueToken(request);
    }
View Full Code Here

     */
    public Element issueToken(String endpointURI, String tokenType) throws WSTrustException {
        if (endpointURI == null && tokenType == null)
            throw logger.nullArgumentError("endpointURI or tokenType");

        RequestSecurityToken request = new RequestSecurityToken();
        if (wsaIssuerAddress != null) {
            request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress));
        }
        setAppliesTo(endpointURI, request);
        setTokenType(tokenType, request);
        return issueToken(request);
    }
View Full Code Here

     */
    public Element issueTokenOnBehalfOf(String endpointURI, String tokenType, Principal principal) throws WSTrustException {
        if (endpointURI == null && tokenType == null)
            throw logger.nullArgumentError("endpointURI or tokenType");

        RequestSecurityToken request = new RequestSecurityToken();
        if (wsaIssuerAddress != null) {
            request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress));
        }
        setAppliesTo(endpointURI, request);
        setTokenType(tokenType, request);
        setOnBehalfOf(principal, request);
        return issueToken(request);
View Full Code Here

     * @return
     * @throws WSTrustException
     */
    public Element renewToken(String tokenType, Element token) throws WSTrustException {
        validateDispatch();
        RequestSecurityToken request = new RequestSecurityToken();
        request.setContext("context");

        request.setTokenType(URI.create(WSTrustConstants.STATUS_TYPE));
        request.setRequestType(URI.create(WSTrustConstants.RENEW_REQUEST));
        RenewTargetType renewTarget = new RenewTargetType();
        renewTarget.add(token);
        request.setRenewTarget(renewTarget);

        // send the token request to JBoss STS and get the response.
        DOMSource requestSource = this.createSourceFromRequest(request);
        Source response = dispatchLocal.get().invoke(requestSource);
        NodeList nodes;
View Full Code Here

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

        RequestSecurityToken requestToken = new RequestSecurityToken();

        QName contextQName = new QName("", WSTrustConstants.RST_CONTEXT);
        Attribute contextAttribute = startElement.getAttributeByName(contextQName);
        if (contextAttribute != null) {
            String contextValue = StaxParserUtil.getAttributeValue(contextAttribute);
            requestToken.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.RST))
                    break;
                else if (endElementTag.equals(WSTrustConstants.SECONDARY_PARAMETERS))
                    continue;
                else if (endElementTag.equals(WSTrustConstants.USE_KEY))
                    continue;
                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 new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "request type");

                    String value = StaxParserUtil.getElementText(xmlEventReader);
                    requestToken.setRequestType(new URI(value));
                } else if (tag.equals(WSTrustConstants.TOKEN_TYPE)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "token type");

                    String value = StaxParserUtil.getElementText(xmlEventReader);
                    requestToken.setTokenType(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 new RuntimeException(ErrorCodes.UNKNOWN_TAG + subTag);

                    requestToken.setLifetime(new Lifetime(lifeTime));
                    EndElement lifeTimeElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(lifeTimeElement, WSTrustConstants.LIFETIME);
                } else if (tag.equals(WSTrustConstants.CANCEL_TARGET)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    StaxParserUtil.validate(subEvent, WSTrustConstants.CANCEL_TARGET);
                    WSTCancelTargetParser wstCancelTargetParser = new WSTCancelTargetParser();
                    CancelTargetType cancelTarget = (CancelTargetType) wstCancelTargetParser.parse(xmlEventReader);
                    requestToken.setCancelTarget(cancelTarget);
                    EndElement cancelTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(cancelTargetEndElement, WSTrustConstants.CANCEL_TARGET);
                } else if (tag.equals(WSTrustConstants.VALIDATE_TARGET)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    WSTValidateTargetParser wstValidateTargetParser = new WSTValidateTargetParser();
                    ValidateTargetType validateTarget = (ValidateTargetType) wstValidateTargetParser.parse(xmlEventReader);
                    requestToken.setValidateTarget(validateTarget);
                    EndElement validateTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(validateTargetEndElement, WSTrustConstants.VALIDATE_TARGET);
                } else if (tag.equals(WSTrustConstants.RENEW_TARGET)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    WSTRenewTargetParser wstValidateTargetParser = new WSTRenewTargetParser();
                    RenewTargetType validateTarget = (RenewTargetType) wstValidateTargetParser.parse(xmlEventReader);
                    requestToken.setRenewTarget(validateTarget);
                    EndElement validateTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(validateTargetEndElement, WSTrustConstants.RENEW_TARGET);
                } else if (tag.equals(WSTrustConstants.ON_BEHALF_OF)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    WSTrustOnBehalfOfParser wstOnBehalfOfParser = new WSTrustOnBehalfOfParser();
                    OnBehalfOfType onBehalfOf = (OnBehalfOfType) wstOnBehalfOfParser.parse(xmlEventReader);
                    requestToken.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 new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "key type");

                    String keyType = StaxParserUtil.getElementText(xmlEventReader);
                    try {
                        URI keyTypeURI = new URI(keyType);
                        requestToken.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 new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "key size");

                    String keySize = StaxParserUtil.getElementText(xmlEventReader);
                    try {
                        requestToken.setKeySize(Long.parseLong(keySize));
                    } catch (NumberFormatException e) {
                        throw new ParsingException(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"));
                        binarySecret.setType(StaxParserUtil.getAttributeValue(typeAttribute));

                        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                            throw new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "binary secret value");

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

                    // Look for addressing
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                    StaxParserUtil.validate(subEvent, WSAddressingConstants.ADDRESS);
                    String addressValue = StaxParserUtil.getElementText(xmlEventReader);

                    EndpointReferenceType endpointRef = new EndpointReferenceType();
                    AttributedURIType attrURI = new AttributedURIType();
                    attrURI.setValue(addressValue);
                    endpointRef.setAddress(new AttributedURIType());
                    requestToken.setIssuer(endpointRef);

                    EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(endElement, WSTrustConstants.ISSUER);
                } else if (tag.equals(WSTrustConstants.SECONDARY_PARAMETERS)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
                } 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);
                        requestToken.setUseKey(useKeyType);
                    } else if (StaxParserUtil.matches(subEvent, KEYVALUE)) {
                        // Element domElement = getKeyValueAsDomElement( subEvent, xmlEventReader );
                        Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);//
                        useKeyType.add(domElement);
                        requestToken.setUseKey(useKeyType);

                        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                        StaxParserUtil.validate(endElement, WSTrustConstants.USE_KEY);
                    } else if (StaxParserUtil.matches(subEvent, XMLDSig.KEYINFO)) {
                        KeyInfoType keyInfo = SAMLParserUtil.parseKeyInfo(xmlEventReader);
                        useKeyType = requestToken.getUseKey();
                        if (useKeyType == null) {
                            useKeyType = new UseKeyType();
                        }
                        useKeyType.add(keyInfo);
                        requestToken.setUseKey(useKeyType);
                    } else
                        throw new RuntimeException(ErrorCodes.UNSUPPORTED_TYPE + StaxParserUtil.getStartElementName(subEvent));
                } else if (tag.equals(WSTrustConstants.COMPUTED_KEY_ALGORITHM)) {
                    subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

                    if (!StaxParserUtil.hasTextAhead(xmlEventReader))
                        throw new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + WSTrustConstants.COMPUTED_KEY_ALGORITHM);

                    String computedKeyAlgo = StaxParserUtil.getElementText(xmlEventReader);

                    requestToken.setComputedKeyAlgorithm(URI.create(computedKeyAlgo));
                } else if (tag.equals(WSTrustConstants.RENEWING)) {
                    requestToken.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) {
                        requestToken.setAppliesTo((AppliesTo) parsedObject);
                    }
                }
            } catch (URISyntaxException e) {
                throw new ParsingException(e);
            }
View Full Code Here

TOP

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

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.