Package org.apache.ws.security.message.token

Examples of org.apache.ws.security.message.token.UsernameToken


        RPCParam arg1 = new RPCParam("urn:myNamespace", "testParam", "this is a string");
        //QName dataQName = new QName("typeNS", "Data");

        Document doc = msg.getAsDocument();

        UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig(),doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");

        RequestSecurityTokenResponse tokenResponse = new RequestSecurityTokenResponse(doc, new SecurityTokenOrReference(userToken));
        tokenResponse.setContext(new URI("http://context.context"));
        tokenResponse.setTokenType(TokenTypes.USERNAME);
   
View Full Code Here


        // Setting the context and the token type we want to be returned
        tokenRequest.setContext(new URI("http://context.context"));
        tokenRequest.setTokenType(TokenTypes.X509);
   
        // Construct a bunch of username tokens to be used as <Base> and <Supporting> elements
        UsernameToken userToken = new UsernameToken(wssConfig, doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");
        tokenRequest.setBase(new SecurityTokenOrReference(userToken));

        UsernameToken user2Token = new UsernameToken(wssConfig, doc);
        user2Token.setName("joe");
        user2Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user2Token));

        UsernameToken user3Token = new UsernameToken(wssConfig, doc);
        user3Token.setName("mike");
        user3Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user3Token));

        // Set the desired Lifetime of the token being requested in this case to 250 seconds
        Date start = new Date();
        Date end = new Date();
View Full Code Here

                        throw new AxisFault("Could not create X.509 Security Token: " + e.getMessage());
                    }
                } else if (TokenTypes.USERNAME.equals(tokenRequest.getTokenType())) {
                    // Create an arbitrary, fixed UsernameToken to return if the client requests one
                    // A real security token service would do something more intelligent
                    UsernameToken userToken = new UsernameToken(WSSConfig.getDefaultWSConfig(),doc);
                    userToken.setName("bob");
                    userToken.setPassword("bobspass");
         
                    // Create a new SecurityTokenOrReference object to use for the <RequestedToken> element
                    // As the class name implies SecurityTokenOrReference objects can hold either a real security token element
                    // or a <SecurityTokenReference> element to a security token found elsewhere
                    requestedToken = new SecurityTokenOrReference(userToken);
View Full Code Here

        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
        try {
            if (el.equals(SecurityTokenReference.SECURITY_TOKEN_REFERENCE))
                this.reference = new SecurityTokenReference(wssConfig, element);
            if (el.equals(UsernameToken.TOKEN))
                this.usernameToken = new UsernameToken(wssConfig, element);
            if (el.equals(BinarySecurity.TOKEN))
                this.binarySecurityToken = new BinarySecurity(wssConfig, element);
            doc = element.getOwnerDocument();
        } catch (WSSecurityException e) {
            throw new ElementParsingException("WSSecurityException while trying to create a SecurityTokenOrReference object from an XML Element: "
View Full Code Here

                if (tokenElement != null) {
                    QName el = new QName(tokenElement.getNamespaceURI(), tokenElement.getLocalName());
                    try {
                        WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
                        if (el.equals(UsernameToken.TOKEN))
                            return new UsernameToken(wssConfig, tokenElement);
                        if (el.equals(BinarySecurity.TOKEN))
                            return new BinarySecurity(wssConfig, tokenElement);
                    } catch (WSSecurityException e) {
                        throw new ElementParsingException("WSSecurityException while trying to create a SecurityToken object from a SecurityTokenReference: "
                                + e.getMessage());
View Full Code Here

   * @param doc
   * @return
   */
  public static UsernameToken findUsernameToken(Document doc){
    try {
    UsernameToken unt;
      //first find base token
      Element elemBase=(Element)WSSecurityUtil.findElement(doc,BaseToken.TOKEN.getLocalPart(),BaseToken.TOKEN.getNamespaceURI());
      Element elemBaseChild=(Element)elemBase.getFirstChild();
      //If the first child is null then return
      if((elemBaseChild==null)){
        return null;
      }
     //If the first child is a UNT
         
      if((elemBaseChild.getLocalName().equals("UsernameToken"))   ){
        unt=new UsernameToken(WSSConfig.getDefaultWSConfig(),elemBaseChild);
        return unt;
      }else{
        return null;
      }
    } catch (WSSecurityException e) {
View Full Code Here

        RequestSecurityToken tokenRequest = new RequestSecurityToken(doc, TrustConstants.REQUEST_ISSUE);

        tokenRequest.setContext(new URI("http://context.context"));
        tokenRequest.setTokenType(TokenTypes.X509);

        UsernameToken userToken = new UsernameToken(wssConfig, doc);
        userToken.setName("bob");
        userToken.setPassword("bobspass");
        tokenRequest.setBase(new SecurityTokenOrReference(userToken));

        UsernameToken user2Token = new UsernameToken(wssConfig, doc);
        user2Token.setName("joe");
        user2Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user2Token));

        UsernameToken user3Token = new UsernameToken(wssConfig, doc);
        user3Token.setName("mike");
        user3Token.setPassword("bobspass");
        tokenRequest.addSupporting(new SecurityTokenOrReference(user3Token));

        WSAddTokenRequest builder = new WSAddTokenRequest(tokenRequest);
        builder.addAction();
        doc = builder.build(doc);
View Full Code Here

     * constructed.
     *
     * @param doc The SOAP envelope as W3C document
     */
    public void prepare(Document doc) {
        ut = new UsernameToken(getWsConfig().isPrecisionInMilliSeconds(), doc,
                               getWsConfig().getCurrentTime(), passwordType);
        ut.setPasswordsAreEncoded(passwordsAreEncoded);
        ut.setName(user);
        if (useDerivedKey) {
            saltValue = ut.addSalt(doc, saltValue, useMac);
View Full Code Here

        int action = ((Integer)result.get(WSSecurityEngineResult.TAG_ACTION)).intValue();
        if (WSConstants.UT_NOPASSWORD == action || WSConstants.UT == action) {
            if (bspCompliant) {
                BSPEnforcer.checkUsernameTokenBSPCompliance(secRef);
            }
            UsernameToken usernameToken =
                (UsernameToken)result.get(WSSecurityEngineResult.TAG_USERNAME_TOKEN);

            usernameToken.setRawPassword(data);
            if (usernameToken.isDerivedKey()) {
                secretKey = (byte[])result.get(WSSecurityEngineResult.TAG_SECRET);
            } else {
                int keyLength = ((Integer)parameters.get(SECRET_KEY_LENGTH)).intValue();
                secretKey = usernameToken.getSecretKey(keyLength);
            }
            principal = usernameToken.createPrincipal();
        } else if (WSConstants.BST == action) {
            if (bspCompliant) {
                BinarySecurity token =
                    (BinarySecurity)result.get(
                        WSSecurityEngineResult.TAG_BINARY_SECURITY_TOKEN
View Full Code Here

            }
        }
       
        Validator validator = data.getValidator(WSSecurityEngine.USERNAME_TOKEN);
        Credential credential = handleUsernameToken(elem, validator, data);
        UsernameToken token = credential.getUsernametoken();
       
        int action = WSConstants.UT;
        byte[] secretKey = null;
        if (token.getPassword() == null) {
            action = WSConstants.UT_NOPASSWORD;
            if (token.isDerivedKey()) {
                token.setRawPassword(data);
                secretKey = token.getDerivedKey();
            }
        }
        WSSecurityEngineResult result = new WSSecurityEngineResult(action, token);
        result.put(WSSecurityEngineResult.TAG_ID, token.getID());
        result.put(WSSecurityEngineResult.TAG_SECRET, secretKey);
       
        if (validator != null) {
            result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
            if (credential.getTransformedToken() != null) {
                result.put(
                    WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN, credential.getTransformedToken()
                );
                if (credential.getPrincipal() != null) {
                    result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
                } else {
                    SAMLTokenPrincipal samlPrincipal =
                        new SAMLTokenPrincipal(credential.getTransformedToken());
                    result.put(WSSecurityEngineResult.TAG_PRINCIPAL, samlPrincipal);
                }
            } else if (credential.getPrincipal() != null) {
                result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
            } else {
                WSUsernameTokenPrincipal principal =
                    new WSUsernameTokenPrincipal(token.getName(), token.isHashed());
                principal.setNonce(token.getNonce());
                principal.setPassword(token.getPassword());
                principal.setCreatedTime(token.getCreated());
                principal.setPasswordType(token.getPasswordType());
                result.put(WSSecurityEngineResult.TAG_PRINCIPAL, principal);
            }
            result.put(WSSecurityEngineResult.TAG_SUBJECT, credential.getSubject());
        }
       
View Full Code Here

TOP

Related Classes of org.apache.ws.security.message.token.UsernameToken

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.