Package org.apache.wss4j.common.principal

Examples of org.apache.wss4j.common.principal.UsernameTokenPrincipal


             * of this token to set the alias for the encryption user
             */
            for (WSSecurityEngineResult wser : wsSecEngineResults) {
                Integer actInt = (Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
                if (actInt.intValue() == WSConstants.UT) {
                    UsernameTokenPrincipal principal
                        = (UsernameTokenPrincipal)wser.get(WSSecurityEngineResult.TAG_PRINCIPAL);
                    return principal.getName();
                }
            }
        }
        
        return null;
View Full Code Here


        List<WSSecurityEngineResult> results = verify(signedDoc, null);
       
        Principal principal = (Principal)results.get(0).get(WSSecurityEngineResult.TAG_PRINCIPAL);
        assertTrue(principal instanceof UsernameTokenPrincipal);
        assertTrue("wernerd".equals(principal.getName()));
        UsernameTokenPrincipal userPrincipal = (UsernameTokenPrincipal)principal;
        assertTrue(userPrincipal.getCreatedTime() != null);
        assertTrue(userPrincipal.getNonce() != null);
        assertTrue(userPrincipal.getPassword() != null);
        assertTrue(userPrincipal.isPasswordDigest());
        assertTrue(WSConstants.PASSWORD_DIGEST.equals(userPrincipal.getPasswordType()));
    }
View Full Code Here

    }

    @Override
    public Principal getPrincipal() throws WSSecurityException {
        if (this.principal == null) {
            this.principal = new UsernameTokenPrincipal() {
                //todo passwordType and passwordDigest return Enum-Type ?
                @Override
                public boolean isPasswordDigest() {
                    return usernameTokenPasswordType == WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST;
                }
View Full Code Here

        Element child = DOMUtils.getFirstElement(el);
        while (child != null) {
            if (SPConstants.USERNAME_TOKEN.equals(child.getLocalName())
                && WSConstants.WSSE_NS.equals(child.getNamespaceURI())) {
                try  {
                    final UsernameTokenPrincipal princ = getPrincipal(child, message);
                    if (princ != null) {
                        List<WSSecurityEngineResult>v = new ArrayList<WSSecurityEngineResult>();
                        int action = WSConstants.UT;
                        if (princ.getPassword() == null) {
                            action = WSConstants.UT_NOPASSWORD;
                        }
                        v.add(0, new WSSecurityEngineResult(action, princ, null, null, null));
                        List<WSHandlerResult> results = CastUtils.cast((List<?>)message
                                                                  .get(WSHandlerConstants.RECV_RESULTS));
                        if (results == null) {
                            results = new ArrayList<WSHandlerResult>();
                            message.put(WSHandlerConstants.RECV_RESULTS, results);
                        }
                        WSHandlerResult rResult = new WSHandlerResult(null, v);
                        results.add(0, rResult);

                        assertTokens(message, princ, false);
                        message.put(WSS4JInInterceptor.PRINCIPAL_RESULT, princ);                  
                       
                        SecurityContext sc = message.get(SecurityContext.class);
                        if (sc == null || sc.getUserPrincipal() == null) {
                            String nonce = null;
                            if (princ.getNonce() != null) {
                                nonce = Base64.encode(princ.getNonce());
                            }
                            Subject subject = createSubject(princ.getName(), princ.getPassword(),
                                princ.isPasswordDigest(), nonce, princ.getCreatedTime());
                            message.put(SecurityContext.class,
                                        createSecurityContext(princ, subject));
                        }

                    }
View Full Code Here

             * of this token to set the alias for the encryption user
             */
            for (WSSecurityEngineResult wser : wsSecEngineResults) {
                Integer actInt = (Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
                if (actInt.intValue() == WSConstants.UT) {
                    UsernameTokenPrincipal principal
                        = (UsernameTokenPrincipal)wser.get(WSSecurityEngineResult.TAG_PRINCIPAL);
                    return principal.getName();
                }
            }
        }
        
        return null;
View Full Code Here

            }
            List<WSSecurityEngineResult> results =
                p.handleToken(tokenElement, data, wsDocInfo);
            return (UsernameTokenPrincipal)results.get(0).get(WSSecurityEngineResult.TAG_PRINCIPAL);
        } else {
            UsernameTokenPrincipal principal = parseTokenAndCreatePrincipal(tokenElement, bspCompliant);
            WSS4JTokenConverter.convertToken(message, principal);
            return principal;
        }
    }
View Full Code Here

       
    }
   
    public static void convertToken(Message msg, Principal p) {
        if (p instanceof UsernameTokenPrincipal) {
            UsernameTokenPrincipal utp = (UsernameTokenPrincipal)p;
            String nonce = null;
            if (utp.getNonce() != null) {
                nonce = Base64Utility.encode(utp.getNonce());
            }
            msg.put(org.apache.cxf.common.security.SecurityToken.class,
                    new UsernameToken(utp.getName(),
                                      utp.getPassword(),
                                      utp.getPasswordType(),
                                      utp.isPasswordDigest(),
                                      nonce,
                                      utp.getCreatedTime()));
           
        }
    }
View Full Code Here

                    if (sc == null || sc.getUserPrincipal() == null) {
                        if (subject != null && principal != null) {
                            message.put(SecurityContext.class,
                                    createSecurityContext(principal, subject));
                        } else if (principal instanceof UsernameTokenPrincipal) {
                            UsernameTokenPrincipal utPrincipal = (UsernameTokenPrincipal)principal;
                            String nonce = null;
                            if (utPrincipal.getNonce() != null) {
                                nonce = Base64.encode(utPrincipal.getNonce());
                            }
                            subject = createSubject(utPrincipal.getName(), utPrincipal.getPassword(),
                                    utPrincipal.isPasswordDigest(), nonce, utPrincipal.getCreatedTime());
                            message.put(SecurityContext.class,
                                    createSecurityContext(utPrincipal, subject));
                        }
                    }
                   
View Full Code Here

             * of this token to set the alias for the encryption user
             */
            for (WSSecurityEngineResult wser : wsSecEngineResults) {
                Integer actInt = (Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
                if (actInt.intValue() == WSConstants.UT) {
                    UsernameTokenPrincipal principal
                        = (UsernameTokenPrincipal)wser.get(WSSecurityEngineResult.TAG_PRINCIPAL);
                    return principal.getName();
                }
            }
        }
        
        return null;
View Full Code Here

             * of this token to set the alias for the encryption user
             */
            for (WSSecurityEngineResult wser : wsSecEngineResults) {
                Integer actInt = (Integer)wser.get(WSSecurityEngineResult.TAG_ACTION);
                if (actInt.intValue() == WSConstants.UT) {
                    UsernameTokenPrincipal principal
                        = (UsernameTokenPrincipal)wser.get(WSSecurityEngineResult.TAG_PRINCIPAL);
                    return principal.getName();
                }
            }
        }
        
        return null;
View Full Code Here

TOP

Related Classes of org.apache.wss4j.common.principal.UsernameTokenPrincipal

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.