Search in sources :

Example 1 with RequestedProofTokenType

use of org.apache.cxf.ws.security.sts.provider.model.RequestedProofTokenType in project cxf by apache.

the class TokenIssueOperation method createResponse.

protected RequestSecurityTokenResponseType createResponse(EncryptionProperties encryptionProperties, TokenProviderResponse tokenResponse, TokenRequirements tokenRequirements, KeyRequirements keyRequirements) throws WSSecurityException {
    RequestSecurityTokenResponseType response = QNameConstants.WS_TRUST_FACTORY.createRequestSecurityTokenResponseType();
    String context = tokenRequirements.getContext();
    if (context != null) {
        response.setContext(context);
    }
    // TokenType
    JAXBElement<String> jaxbTokenType = QNameConstants.WS_TRUST_FACTORY.createTokenType(tokenRequirements.getTokenType());
    response.getAny().add(jaxbTokenType);
    // RequestedSecurityToken
    RequestedSecurityTokenType requestedTokenType = QNameConstants.WS_TRUST_FACTORY.createRequestedSecurityTokenType();
    JAXBElement<RequestedSecurityTokenType> requestedToken = QNameConstants.WS_TRUST_FACTORY.createRequestedSecurityToken(requestedTokenType);
    tokenWrapper.wrapToken(tokenResponse.getToken(), requestedTokenType);
    response.getAny().add(requestedToken);
    if (returnReferences) {
        // RequestedAttachedReference
        TokenReference attachedReference = tokenResponse.getAttachedReference();
        RequestedReferenceType requestedAttachedReferenceType = null;
        if (attachedReference != null) {
            requestedAttachedReferenceType = createRequestedReference(attachedReference, true);
        } else {
            requestedAttachedReferenceType = createRequestedReference(tokenResponse.getTokenId(), tokenRequirements.getTokenType(), true);
        }
        JAXBElement<RequestedReferenceType> requestedAttachedReference = QNameConstants.WS_TRUST_FACTORY.createRequestedAttachedReference(requestedAttachedReferenceType);
        response.getAny().add(requestedAttachedReference);
        // RequestedUnattachedReference
        TokenReference unAttachedReference = tokenResponse.getUnAttachedReference();
        RequestedReferenceType requestedUnattachedReferenceType = null;
        if (unAttachedReference != null) {
            requestedUnattachedReferenceType = createRequestedReference(unAttachedReference, false);
        } else {
            requestedUnattachedReferenceType = createRequestedReference(tokenResponse.getTokenId(), tokenRequirements.getTokenType(), false);
        }
        JAXBElement<RequestedReferenceType> requestedUnattachedReference = QNameConstants.WS_TRUST_FACTORY.createRequestedUnattachedReference(requestedUnattachedReferenceType);
        response.getAny().add(requestedUnattachedReference);
    }
    // AppliesTo
    response.getAny().add(tokenRequirements.getAppliesTo());
    // RequestedProofToken
    if (tokenResponse.isComputedKey() && keyRequirements.getComputedKeyAlgorithm() != null) {
        JAXBElement<String> computedKey = QNameConstants.WS_TRUST_FACTORY.createComputedKey(keyRequirements.getComputedKeyAlgorithm());
        RequestedProofTokenType requestedProofTokenType = QNameConstants.WS_TRUST_FACTORY.createRequestedProofTokenType();
        requestedProofTokenType.setAny(computedKey);
        JAXBElement<RequestedProofTokenType> requestedProofToken = QNameConstants.WS_TRUST_FACTORY.createRequestedProofToken(requestedProofTokenType);
        response.getAny().add(requestedProofToken);
    } else if (tokenResponse.getEntropy() != null) {
        Object token = constructSecretToken(tokenResponse.getEntropy(), encryptionProperties, keyRequirements);
        RequestedProofTokenType requestedProofTokenType = QNameConstants.WS_TRUST_FACTORY.createRequestedProofTokenType();
        requestedProofTokenType.setAny(token);
        JAXBElement<RequestedProofTokenType> requestedProofToken = QNameConstants.WS_TRUST_FACTORY.createRequestedProofToken(requestedProofTokenType);
        response.getAny().add(requestedProofToken);
    }
    // Entropy
    if (tokenResponse.isComputedKey() && tokenResponse.getEntropy() != null) {
        Object token = constructSecretToken(tokenResponse.getEntropy(), encryptionProperties, keyRequirements);
        EntropyType entropyType = QNameConstants.WS_TRUST_FACTORY.createEntropyType();
        entropyType.getAny().add(token);
        JAXBElement<EntropyType> entropyElement = QNameConstants.WS_TRUST_FACTORY.createEntropy(entropyType);
        response.getAny().add(entropyElement);
    }
    // Lifetime
    if (includeLifetimeElement) {
        LifetimeType lifetime = createLifetime(tokenResponse.getCreated(), tokenResponse.getExpires());
        JAXBElement<LifetimeType> lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetime(lifetime);
        response.getAny().add(lifetimeType);
    }
    // KeySize
    long keySize = tokenResponse.getKeySize();
    if (keySize <= 0) {
        keySize = keyRequirements.getKeySize();
    }
    if (keyRequirements.getKeySize() > 0) {
        JAXBElement<Long> keySizeType = QNameConstants.WS_TRUST_FACTORY.createKeySize(keySize);
        response.getAny().add(keySizeType);
    }
    return response;
}
Also used : RequestedProofTokenType(org.apache.cxf.ws.security.sts.provider.model.RequestedProofTokenType) RequestedReferenceType(org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType) RequestSecurityTokenResponseType(org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType) RequestedSecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType) JAXBElement(javax.xml.bind.JAXBElement) EntropyType(org.apache.cxf.ws.security.sts.provider.model.EntropyType) LifetimeType(org.apache.cxf.ws.security.sts.provider.model.LifetimeType) TokenReference(org.apache.cxf.sts.token.provider.TokenReference)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)1 TokenReference (org.apache.cxf.sts.token.provider.TokenReference)1 EntropyType (org.apache.cxf.ws.security.sts.provider.model.EntropyType)1 LifetimeType (org.apache.cxf.ws.security.sts.provider.model.LifetimeType)1 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)1 RequestedProofTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestedProofTokenType)1 RequestedReferenceType (org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType)1 RequestedSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType)1