Package org.apache.cxf.ws.security.tokenstore

Examples of org.apache.cxf.ws.security.tokenstore.SecurityToken


                    (KerberosSecurity)wser.get(WSSecurityEngineResult.TAG_BINARY_SECURITY_TOKEN);
                KerberosTokenPolicyValidator kerberosValidator =
                    new KerberosTokenPolicyValidator(message);
                boolean valid = kerberosValidator.validatePolicy(aim, kerberosToken);
                if (valid) {
                    SecurityToken token = createSecurityToken(kerberosToken);
                    token.setSecret((byte[])wser.get(WSSecurityEngineResult.TAG_SECRET));
                    message.getExchange().put(SecurityConstants.TOKEN, token);
                    return;
                }
            }
        }
View Full Code Here


                            pc.setKey(token.getSecret());
                            return;
                        }
                    }                   
                } else {
                    SecurityToken tok = store.getToken(id);
                    if (tok != null) {
                        pc.setKey(tok.getSecret());
                        pc.setCustomToken(tok.getToken());
                        return;
                    }
                }
            }
            if (internal != null) {
View Full Code Here

            }
            if (isRequestor(message)) {
                SecureConversationToken itok = (SecureConversationToken)ais.iterator()
                    .next().getAssertion();
               
                SecurityToken tok = (SecurityToken)message.getContextualProperty(SecurityConstants.TOKEN);
                if (tok == null) {
                    String tokId = (String)message.getContextualProperty(SecurityConstants.TOKEN_ID);
                    if (tokId != null) {
                        tok = SecureConversationTokenInterceptorProvider
                            .getTokenStore(message).getToken(tokId);
                    }
                }
                if (tok == null) {
                    tok = issueToken(message, aim, itok);
                } else {
                    renewToken(message, aim, tok, itok);
                }
                if (tok != null) {
                    for (AssertionInfo ai : ais) {
                        ai.setAsserted(true);
                    }
                    message.getExchange().get(Endpoint.class).put(SecurityConstants.TOKEN_ID,
                                                                  tok.getId());
                    message.getExchange().put(SecurityConstants.TOKEN_ID,
                                              tok.getId());
                    SecureConversationTokenInterceptorProvider.getTokenStore(message).add(tok);
                   
                }
            } else {
                //server side should be checked on the way in
View Full Code Here

        synchronized (client) {
            try {
                String s = SecureConversationTokenInterceptorProvider
                    .setupClient(client, message, aim, itok, false);

                SecurityToken tok = null;
                if (maps != null) {
                    client.setAddressingNamespace(maps.getNamespaceURI());
                }
                tok = client.requestSecurityToken(s);
                tok.setTokenType(WSConstants.WSC_SCT);
                return tok;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new Fault(e);
View Full Code Here

           
            if (encryptionToken != null && encrParts.size() > 0) {
                //The encryption token can be an IssuedToken or a
                 //SecureConversationToken
                String tokenId = null;
                SecurityToken tok = null;
                if (encryptionToken instanceof IssuedToken) {
                    tok = getSecurityToken();
                } else if (encryptionToken instanceof SecureConversationToken) {
                    tok = getSecurityToken();
                } else if (encryptionToken instanceof X509Token) {
                    if (isRequestor()) {
                        tokenId = setupEncryptedKey(encryptionWrapper, encryptionToken);
                    } else {
                        tokenId = getEncryptedKey();
                    }
                }
                if (tok == null) {
                    if (tokenId == null || tokenId.length() == 0) {
                        //REVISIT - no tokenId?   Exception?
                    }
                    if (tokenId.startsWith("#")) {
                        tokenId = tokenId.substring(1);
                    }
                   
                    /*
                     * Get hold of the token from the token storage
                     */
                    tok = tokenStore.getToken(tokenId);
                }
   
                boolean attached = false;
               
                if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == encryptionToken.getInclusion()
                    || SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == encryptionToken.getInclusion()
                    || (isRequestor()
                        && SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
                            == encryptionToken.getInclusion())) {
                   
                    Element el = tok.getToken();
                    this.addEncyptedKeyElement(cloneElement(el));
                    attached = true;
                } else if (encryptionToken instanceof X509Token && isRequestor()) {
                    Element el = tok.getToken();
                    this.addEncyptedKeyElement(cloneElement(el));
                    attached = true;
                }
               
                WSSecBase encr = doEncryption(encryptionWrapper, tok, attached, encrParts, true);
View Full Code Here

       
        String sigTokId = null;
        Element sigTokElem = null;
       
        try {
            SecurityToken sigTok = null;
            if (sigToken != null) {
                if (sigToken instanceof SecureConversationToken) {
                    sigTok = getSecurityToken();
                } else if (sigToken instanceof IssuedToken) {
                    sigTok = getSecurityToken();
                } else if (sigToken instanceof X509Token) {
                    if (isRequestor()) {
                        sigTokId = setupEncryptedKey(sigTokenWrapper, sigToken);
                    } else {
                        sigTokId = getEncryptedKey();
                    }
                }
            } else {
                policyNotAsserted(sbinding, "No signature token");
                return;
            }
           
            if (sigTok == null && StringUtils.isEmpty(sigTokId)) {
                policyNotAsserted(sigTokenWrapper, "No signature token id");
                return;
            } else {
                policyAsserted(sigTokenWrapper);
            }
            if (sigTok == null) {
                sigTok = tokenStore.getToken(sigTokId);
            }
            if (sigTok == null) {
                //REVISIT - no token?
            }
            boolean tokIncluded = true;
            if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == sigToken.getInclusion()
                || SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == sigToken.getInclusion()
                || (isRequestor()
                    && SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
                        == sigToken.getInclusion())) {
               
                Element el = sigTok.getToken();
                sigTokElem = cloneElement(el);
                this.addEncyptedKeyElement((Element)sigTokElem);
            } else if (isRequestor() && sigToken instanceof X509Token) {
                Element el = sigTok.getToken();
                sigTokElem = (Element)secHeader.getSecurityHeader().getOwnerDocument()
                        .importNode(el, true);
                this.addEncyptedKeyElement((Element)sigTokElem);
            } else {
                tokIncluded = false;
            }
       
       
            Vector<WSEncryptionPart> sigs = getSignedParts();
            //Add timestamp
            if (timestampEl != null) {
                Element el = timestampEl.getElement();
                sigs.add(new WSEncryptionPart(addWsuIdToElement(el)));
            }

            if (isRequestor()) {
                addSupportingTokens(sigs);
                if (!sigs.isEmpty()) {
                    signatures.add(doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded));
                }
                doEndorse();
            } else {
                //confirm sig
                assertSupportingTokens(sigs);
                addSignatureConfirmation(sigs);
                if (!sigs.isEmpty()) {
                    doSignature(sigs, sigTokenWrapper, sigToken, sigTok, tokIncluded);
                }
            }

           
           
            //Encryption
            TokenWrapper encrTokenWrapper = getEncryptionToken();
            Token encrToken = encrTokenWrapper.getToken();
            SecurityToken encrTok = null;
            if (sigToken.equals(encrToken)) {
                //Use the same token
                encrTok = sigTok;
            } else {
                String encrTokId = null;
                //REVISIT - issued token from trust?
                encrTok = tokenStore.getToken(encrTokId);
               
                if (SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS == encrToken.getInclusion()
                    || SPConstants.IncludeTokenType.INCLUDE_TOKEN_ONCE == encrToken.getInclusion()
                    || (isRequestor()
                            && SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT
                            == encrToken.getInclusion())) {
                    Element encrTokElem = (Element)encrTok.getToken();
                   
                    //Add the encrToken element before the sigToken element
                    secHeader.getSecurityHeader().insertBefore(encrTokElem, sigTokElem);
                }
            }
View Full Code Here

        byte[] secret = encrKey.getEphemeralKey();

        Calendar created = Calendar.getInstance();
        Calendar expires = Calendar.getInstance();
        expires.setTimeInMillis(System.currentTimeMillis() + 300000);
        SecurityToken tempTok = new SecurityToken(
                        id,
                        encrKey.getEncryptedKeyElement(),
                        created,
                        expires);
       
       
        tempTok.setSecret(secret);
       
        // Set the SHA1 value of the encrypted key, this is used when the encrypted
        // key is referenced via a key identifier of type EncryptedKeySHA1
        tempTok.setSHA1(getSHA1(encrKey.getEncryptedEphemeralKey()));
       
        tokenStore.add(tempTok);
       
        String bstTokenId = encrKey.getBSTTokenId();
        //If direct ref is used to refer to the cert
View Full Code Here

                    String encryptedKeyID = (String)wser.get(WSSecurityEngineResult.TAG_ENCRYPTED_KEY_ID);
                           
                    Calendar created = Calendar.getInstance();
                    Calendar expires = Calendar.getInstance();
                    expires.setTimeInMillis(System.currentTimeMillis() + 300000);
                    SecurityToken tempTok = new SecurityToken(encryptedKeyID, created, expires);
                    tempTok.setSecret((byte[])wser.get(WSSecurityEngineResult.TAG_DECRYPTED_KEY));
                    tempTok.setSHA1(getSHA1((byte[])wser
                                            .get(WSSecurityEngineResult.TAG_ENCRYPTED_EPHEMERAL_KEY)));
                    tokenStore.add(tempTok);
                   
                    return encryptedKeyID;
                }
View Full Code Here

                    return;
                }
                if (isRequestor(message)) {
                    IssuedToken itok = (IssuedToken)ais.iterator().next().getAssertion();
                   
                    SecurityToken tok = (SecurityToken)message.getContextualProperty(SecurityConstants.TOKEN);
                    if (tok == null) {
                        String tokId = (String)message.getContextualProperty(SecurityConstants.TOKEN_ID);
                        if (tokId != null) {
                            tok = getTokenStore(message).getToken(tokId);
                        }
                    }
                    if (tok == null) {
                        STSClient client = getClient(message);
                        AddressingProperties maps =
                            (AddressingProperties)message
                                .get("javax.xml.ws.addressing.context.outbound");
                        if (maps == null) {
                            maps = (AddressingProperties)message
                                .get("javax.xml.ws.addressing.context");
                        }
                        synchronized (client) {
                            try {
                                client.setTrust(getTrust10(aim));
                                client.setTrust(getTrust13(aim));
                                client.setTemplate(itok.getRstTemplate());
                                if (maps == null) {
                                    tok = client.requestSecurityToken();
                                } else {
                                    Object o = message
                                        .getContextualProperty(SecurityConstants.STS_APPLIES_TO);
                                    String s = o == null ? null : o.toString();
                                    s = s == null
                                        ? message.getContextualProperty(Message.ENDPOINT_ADDRESS).toString()
                                            : s;
                                    client.setAddressingNamespace(maps.getNamespaceURI());
                                    tok = client.requestSecurityToken(s);
                                }
                            } catch (RuntimeException e) {
                                throw e;
                            } catch (Exception e) {
                                throw new Fault(e);
                            } finally {
                                client.setTrust((Trust10)null);
                                client.setTrust((Trust13)null);
                                client.setTemplate(null);
                                client.setAddressingNamespace(null);
                            }
                        }
                    } else {
                        //renew token?
                    }
                    if (tok != null) {
                        for (AssertionInfo ai : ais) {
                            ai.setAsserted(true);
                        }
                        message.getExchange().get(Endpoint.class).put(SecurityConstants.TOKEN_ID,
                                                                      tok.getId());
                        message.getExchange().put(SecurityConstants.TOKEN_ID,
                                                  tok.getId());
                        getTokenStore(message).add(tok);
                    }
                } else {
                    //server side should be checked on the way in
                    for (AssertionInfo ai : ais) {
View Full Code Here

                        for (int i = 0; i < results.size(); i++) {
                            WSHandlerResult rResult =
                                    (WSHandlerResult) results.get(i);
   
                            Vector wsSecEngineResults = rResult.getResults();
                            SecurityToken token = findIssuedToken(wsSecEngineResults);
                            if (token != null) {
                                found = true;
                                message.getExchange().put(SecurityConstants.TOKEN, token);
                            }
                        }
View Full Code Here

TOP

Related Classes of org.apache.cxf.ws.security.tokenstore.SecurityToken

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.