Search in sources :

Example 1 with StatusType

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

the class TokenValidateOperation method createResponse.

protected RequestSecurityTokenResponseType createResponse(TokenValidatorResponse tokenResponse, TokenProviderResponse tokenProviderResponse, TokenRequirements tokenRequirements) throws WSSecurityException {
    RequestSecurityTokenResponseType response = QNameConstants.WS_TRUST_FACTORY.createRequestSecurityTokenResponseType();
    String context = tokenRequirements.getContext();
    if (context != null) {
        response.setContext(context);
    }
    // TokenType
    boolean valid = tokenResponse.getToken().getState() == STATE.VALID;
    String tokenType = tokenRequirements.getTokenType();
    if (valid || STSConstants.STATUS.equals(tokenType)) {
        JAXBElement<String> jaxbTokenType = QNameConstants.WS_TRUST_FACTORY.createTokenType(tokenType);
        response.getAny().add(jaxbTokenType);
    }
    // Status
    StatusType statusType = QNameConstants.WS_TRUST_FACTORY.createStatusType();
    if (valid) {
        statusType.setCode(STSConstants.VALID_CODE);
        statusType.setReason(STSConstants.VALID_REASON);
    } else {
        statusType.setCode(STSConstants.INVALID_CODE);
        statusType.setReason(STSConstants.INVALID_REASON);
    }
    JAXBElement<StatusType> status = QNameConstants.WS_TRUST_FACTORY.createStatus(statusType);
    response.getAny().add(status);
    // RequestedSecurityToken
    if (valid && !STSConstants.STATUS.equals(tokenType) && tokenProviderResponse != null && tokenProviderResponse.getToken() != null) {
        RequestedSecurityTokenType requestedTokenType = QNameConstants.WS_TRUST_FACTORY.createRequestedSecurityTokenType();
        JAXBElement<RequestedSecurityTokenType> requestedToken = QNameConstants.WS_TRUST_FACTORY.createRequestedSecurityToken(requestedTokenType);
        tokenWrapper.wrapToken(tokenProviderResponse.getToken(), requestedTokenType);
        response.getAny().add(requestedToken);
        // Lifetime
        if (includeLifetimeElement) {
            LifetimeType lifetime = createLifetime(tokenProviderResponse.getCreated(), tokenProviderResponse.getExpires());
            JAXBElement<LifetimeType> lifetimeType = QNameConstants.WS_TRUST_FACTORY.createLifetime(lifetime);
            response.getAny().add(lifetimeType);
        }
        if (returnReferences) {
            // RequestedAttachedReference
            TokenReference attachedReference = tokenProviderResponse.getAttachedReference();
            final RequestedReferenceType requestedAttachedReferenceType;
            if (attachedReference != null) {
                requestedAttachedReferenceType = createRequestedReference(attachedReference, true);
            } else {
                requestedAttachedReferenceType = createRequestedReference(tokenProviderResponse.getTokenId(), tokenRequirements.getTokenType(), true);
            }
            JAXBElement<RequestedReferenceType> requestedAttachedReference = QNameConstants.WS_TRUST_FACTORY.createRequestedAttachedReference(requestedAttachedReferenceType);
            response.getAny().add(requestedAttachedReference);
            // RequestedUnattachedReference
            TokenReference unAttachedReference = tokenProviderResponse.getUnAttachedReference();
            final RequestedReferenceType requestedUnattachedReferenceType;
            if (unAttachedReference != null) {
                requestedUnattachedReferenceType = createRequestedReference(unAttachedReference, false);
            } else {
                requestedUnattachedReferenceType = createRequestedReference(tokenProviderResponse.getTokenId(), tokenRequirements.getTokenType(), false);
            }
            JAXBElement<RequestedReferenceType> requestedUnattachedReference = QNameConstants.WS_TRUST_FACTORY.createRequestedUnattachedReference(requestedUnattachedReferenceType);
            response.getAny().add(requestedUnattachedReference);
        }
    }
    return response;
}
Also used : 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) StatusType(org.apache.cxf.ws.security.sts.provider.model.StatusType) LifetimeType(org.apache.cxf.ws.security.sts.provider.model.LifetimeType) TokenReference(org.apache.cxf.sts.token.provider.TokenReference)

Aggregations

TokenReference (org.apache.cxf.sts.token.provider.TokenReference)1 LifetimeType (org.apache.cxf.ws.security.sts.provider.model.LifetimeType)1 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)1 RequestedReferenceType (org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType)1 RequestedSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType)1 StatusType (org.apache.cxf.ws.security.sts.provider.model.StatusType)1