Examples of UsernameTokenType


Examples of org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType

        TokenValidator usernameTokenValidator = new UsernameTokenValidator();
        TokenValidatorParameters validatorParameters = createValidatorParameters();
        TokenRequirements tokenRequirements = validatorParameters.getTokenRequirements();
       
        // Create a ValidateTarget consisting of a UsernameToken
        UsernameTokenType usernameToken = new UsernameTokenType();
        AttributedString username = new AttributedString();
        username.setValue("alice");
        usernameToken.setUsername(username);
        JAXBElement<UsernameTokenType> tokenType =
            new JAXBElement<UsernameTokenType>(
                QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameToken
            );
       
        // Create a WSS4J UsernameToken
        Document doc = DOMUtils.createDocument();
        UsernameToken ut = new UsernameToken(true, doc, WSConstants.PASSWORD_DIGEST);
        ut.setName("alice");
        ut.setPassword("clarinet");
        ut.addNonce(doc);
        ut.addCreated(true, doc);

        // Add a password
        PasswordString password = new PasswordString();
        password.setValue(ut.getPassword());
        password.setType(WSConstants.PASSWORD_DIGEST);
        JAXBElement<PasswordString> passwordType =
            new JAXBElement<PasswordString>(
                QNameConstants.PASSWORD, PasswordString.class, password
            );
        usernameToken.getAny().add(passwordType);
       
        // Add a nonce
        EncodedString nonce = new EncodedString();
        nonce.setValue(ut.getNonce());
        nonce.setEncodingType(WSConstants.SOAPMESSAGE_NS + "#Base64Binary");
        JAXBElement<EncodedString> nonceType =
            new JAXBElement<EncodedString>(
                QNameConstants.NONCE, EncodedString.class, nonce
            );
        usernameToken.getAny().add(nonceType);
       
        // Add Created value
        String created = ut.getCreated();
        Element createdElement = doc.createElementNS(WSConstants.WSU_NS, "Created");
        createdElement.setAttributeNS(WSConstants.XMLNS_NS, "xmlns", WSConstants.WSU_NS);
        createdElement.setTextContent(created);
        usernameToken.getAny().add(createdElement);
       
        ReceivedToken validateTarget = new ReceivedToken(tokenType);
        tokenRequirements.setValidateTarget(validateTarget);
        validatorParameters.setToken(validateTarget);
       
View Full Code Here

Examples of org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType

     */
    @org.junit.Test
    public void testDefaultSaml1ActAsUsernameToken() throws Exception {
        TokenProvider samlTokenProvider = new SAMLTokenProvider();
       
        UsernameTokenType usernameToken = new UsernameTokenType();
        AttributedString username = new AttributedString();
        username.setValue("bob");
        usernameToken.setUsername(username);
        JAXBElement<UsernameTokenType> usernameTokenType =
            new JAXBElement<UsernameTokenType>(
                QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameToken
            );
       
View Full Code Here

Examples of org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType

     */
    @org.junit.Test
    public void testCustomHandlingUsernameToken() throws Exception {
        TokenProvider samlTokenProvider = new SAMLTokenProvider();
       
        UsernameTokenType usernameToken = new UsernameTokenType();
        AttributedString username = new AttributedString();
        username.setValue("bob");
        usernameToken.setUsername(username);
        JAXBElement<UsernameTokenType> usernameTokenType =
            new JAXBElement<UsernameTokenType>(
                QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameToken
            );
       
View Full Code Here

Examples of org.apache.wss4j.binding.wss10.UsernameTokenType

    @Override
    public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
                       Deque<XMLSecEvent> eventQueue, Integer index) throws XMLSecurityException {

        @SuppressWarnings("unchecked")
        final UsernameTokenType usernameTokenType =
                ((JAXBElement<UsernameTokenType>) parseStructure(eventQueue, index, securityProperties)).getValue();

        final List<XMLSecEvent> xmlSecEvents = getResponsibleXMLSecEvents(eventQueue, index);

        checkBSPCompliance(inputProcessorChain, usernameTokenType, xmlSecEvents);

        if (usernameTokenType.getId() == null) {
            usernameTokenType.setId(IDGenerator.generateID(null));
        }
       
        // Verify Created
        final WSSSecurityProperties wssSecurityProperties = (WSSSecurityProperties) securityProperties;
        Date createdDate = verifyCreated(wssSecurityProperties, usernameTokenType);

        ReplayCache replayCache = wssSecurityProperties.getNonceReplayCache();
        final EncodedString encodedNonce =
                XMLSecurityUtils.getQNameType(usernameTokenType.getAny(), WSSConstants.TAG_wsse_Nonce);
        if (encodedNonce != null && replayCache != null) {
            // Check for replay attacks
            String nonce = encodedNonce.getValue();
            if (replayCache.contains(nonce)) {
                throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION);
            }
           
            // If no Created, then just cache for the default time
            // Otherwise, cache for the configured TTL of the UsernameToken Created time, as any
            // older token will just get rejected anyway
            int utTTL = wssSecurityProperties.getUtTTL();
            if (createdDate == null || utTTL <= 0) {
                replayCache.add(nonce);
            } else {
                replayCache.add(nonce, utTTL + 1L);
            }
        }

        final WSInboundSecurityContext wsInboundSecurityContext = (WSInboundSecurityContext) inputProcessorChain.getSecurityContext();
        final List<QName> elementPath = getElementPath(eventQueue);
       
        final TokenContext tokenContext = new TokenContext(wssSecurityProperties, wsInboundSecurityContext, xmlSecEvents, elementPath);

        UsernameTokenValidator usernameTokenValidator =
                wssSecurityProperties.getValidator(WSSConstants.TAG_wsse_UsernameToken);
        if (usernameTokenValidator == null) {
            usernameTokenValidator = new UsernameTokenValidatorImpl();
        }
        //jdk 1.6 compiler bug? http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
        //type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with
        // upper bounds org.apache.wss4j.stax.securityToken.UsernameSecurityToken,
        // org.apache.wss4j.stax.securityToken.UsernameSecurityToken,
        // org.apache.xml.security.stax.ext.securityToken.InboundSecurityToken
        //works fine on jdk 1.7
        final UsernameSecurityToken usernameSecurityToken =
                usernameTokenValidator.</*fake @see above*/UsernameSecurityTokenImpl>
                        validate(usernameTokenType, tokenContext);

        SecurityTokenProvider<InboundSecurityToken> securityTokenProvider =
                new SecurityTokenProvider<InboundSecurityToken>() {

            @Override
            public InboundSecurityToken getSecurityToken() throws XMLSecurityException {
                return (InboundSecurityToken)usernameSecurityToken;
            }

            @Override
            public String getId() {
                return usernameTokenType.getId();
            }
        };
        inputProcessorChain.getSecurityContext().registerSecurityTokenProvider(usernameTokenType.getId(), securityTokenProvider);

        //fire a tokenSecurityEvent
        UsernameTokenSecurityEvent usernameTokenSecurityEvent = new UsernameTokenSecurityEvent();
        usernameTokenSecurityEvent.setSecurityToken((UsernameSecurityToken)securityTokenProvider.getSecurityToken());
        // usernameTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
        usernameTokenSecurityEvent.setCorrelationID(usernameTokenType.getId());
        inputProcessorChain.getSecurityContext().registerSecurityEvent(usernameTokenSecurityEvent);
    }
View Full Code Here

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

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

     * @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

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

     * @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

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

                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

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

     * @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

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

        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
TOP
Copyright © 2018 www.massapi.com. 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.