Package org.picketlink.identity.federation.ws.wss.secext

Examples of org.picketlink.identity.federation.ws.wss.secext.UsernameTokenType


      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);
    }
View Full Code Here


     * @return a {@code Principal} representing the extracted identity, or {@code null} if the contents of the
     *         {@code OnBehalfOf} element could not be parsed.
     */
    public static Principal getOnBehalfOfPrincipal(OnBehalfOfType onBehalfOf) {
        // if OnBehalfOfType contains a username token, return this username in the form of a principal.
        UsernameTokenType usernameToken = null;
        List<Object> theList = onBehalfOf.getAny();
        for (Object content : theList) {
            if (content instanceof UsernameTokenType)
                usernameToken = (UsernameTokenType) content;
            else if (content instanceof JAXBElement) {
                JAXBElement<?> element = (JAXBElement<?>) content;
                if (element.getName().getLocalPart().equalsIgnoreCase("UsernameToken"))
                    usernameToken = (UsernameTokenType) element.getValue();
            }
        }
        /*
         * Object content = onBehalfOf.getAny(); if (content instanceof UsernameTokenType) usernameToken = (UsernameTokenType)
         * content; else if (content instanceof JAXBElement) { JAXBElement<?> element = (JAXBElement<?>) content; if
         * (element.getName().getLocalPart().equalsIgnoreCase("UsernameToken")) usernameToken = (UsernameTokenType)
         * element.getValue(); }
         */
        if (usernameToken != null && usernameToken.getUsername() != null) {
            final String username = usernameToken.getUsername().getValue();
            return new Principal() {
                public String getName() {
                    return username;
                }
            };
View Full Code Here

     * @return the constructed {@code OnBehalfOfType} instance.
     */
    public static OnBehalfOfType createOnBehalfOfWithUsername(String username, String id) {
        AttributedString attrString = new AttributedString();
        attrString.setValue(username);
        UsernameTokenType usernameToken = new UsernameTokenType();
        usernameToken.setId(id);
        usernameToken.setUsername(attrString);
        // create the OnBehalfOfType and set the UsernameTokenType.
        OnBehalfOfType onBehalfOf = new OnBehalfOfType();
        onBehalfOf.add(usernameToken);
        return onBehalfOf;
    }
View Full Code Here

                String elementName = StaxParserUtil.getStartElementName(startElement);
                if (elementName.equalsIgnoreCase(WSTrustConstants.WSSE.USERNAME_TOKEN)) {
                    startElement = StaxParserUtil.getNextStartElement(xmlEventReader);

                    UsernameTokenType userNameToken = new UsernameTokenType();

                    // Get the Id attribute
                    QName idQName = new QName(WSTrustConstants.WSU_NS, WSTrustConstants.WSSE.ID);
                    Attribute idAttribute = startElement.getAttributeByName(idQName);

                    if (idAttribute == null)
                        throw logger.parserRequiredAttribute("Id");

                    userNameToken.setId(StaxParserUtil.getAttributeValue(idAttribute));

                    startElement = StaxParserUtil.getNextStartElement(xmlEventReader);

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

                    String userName = StaxParserUtil.getElementText(xmlEventReader);

                    AttributedString attributedString = new AttributedString();
                    attributedString.setValue(userName);

                    userNameToken.setUsername(attributedString);

                    // Get the end element
                    EndElement onBehalfOfEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                    StaxParserUtil.validate(onBehalfOfEndElement, WSTrustConstants.WSSE.USERNAME_TOKEN);
View Full Code Here

     * @param out
     * @throws ProcessingException
     */
    private void writeOnBehalfOfType(OnBehalfOfType onBehalfOf) throws ProcessingException {
        StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.ON_BEHALF_OF, BASE_NAMESPACE);
        UsernameTokenType usernameToken = (UsernameTokenType) onBehalfOf.getAny().get(0);
        WSSecurityWriter wsseWriter = new WSSecurityWriter(this.writer);
        wsseWriter.write(usernameToken);
        StaxUtil.writeEndElement(writer);
    }
View Full Code Here

        String tag = StaxParserUtil.getStartElementName(startElement);

        if (tag.equals(WSTrustConstants.WSSE.USERNAME_TOKEN)) {
            WSSecurityParser wsseParser = new WSSecurityParser();

            UsernameTokenType userNameToken = (UsernameTokenType) wsseParser.parse(xmlEventReader);
            onBehalfType.add(userNameToken);
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());

        return onBehalfType;
View Full Code Here

        assertEquals(WSTrustConstants.ISSUE_REQUEST, requestToken.getRequestType().toASCIIString());

        OnBehalfOfType onBehalfOf = requestToken.getOnBehalfOf();
        List<Object> theList = onBehalfOf.getAny();
        assertNotNull(theList);
        UsernameTokenType userNameToken = (UsernameTokenType) theList.get(0);
        assertEquals("id", userNameToken.getId());
        assertEquals("anotherduke", userNameToken.getUsername().getValue());

        // Now for the writing part
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WSTrustRequestWriter rstWriter = new WSTrustRequestWriter(baos);
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.ws.wss.secext.UsernameTokenType

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.