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;
}
Aggregations