Search in sources :

Example 1 with KeyIdentifierType

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

the class AbstractOperation method createRequestedReference.

/**
 * Create a RequestedReferenceType object using a TokenReference object
 */
protected static RequestedReferenceType createRequestedReference(TokenReference tokenReference, boolean attached) {
    RequestedReferenceType requestedReferenceType = QNameConstants.WS_TRUST_FACTORY.createRequestedReferenceType();
    SecurityTokenReferenceType securityTokenReferenceType = QNameConstants.WSSE_FACTORY.createSecurityTokenReferenceType();
    // TokenType
    String tokenType = tokenReference.getWsse11TokenType();
    if (tokenType != null) {
        securityTokenReferenceType.getOtherAttributes().put(TOKEN_TYPE, tokenType);
    }
    if (tokenReference.isUseKeyIdentifier()) {
        String identifier = XMLUtils.getIDFromReference(tokenReference.getIdentifier());
        KeyIdentifierType keyIdentifierType = QNameConstants.WSSE_FACTORY.createKeyIdentifierType();
        keyIdentifierType.setValue(identifier);
        String valueType = tokenReference.getWsseValueType();
        if (valueType != null) {
            keyIdentifierType.setValueType(valueType);
        }
        JAXBElement<KeyIdentifierType> keyIdentifier = QNameConstants.WSSE_FACTORY.createKeyIdentifier(keyIdentifierType);
        securityTokenReferenceType.getAny().add(keyIdentifier);
    } else if (tokenReference.isUseDirectReference()) {
        String identifier = tokenReference.getIdentifier();
        if (attached && identifier.charAt(0) != '#') {
            identifier = "#" + identifier;
        } else if (!attached && identifier.charAt(0) == '#') {
            identifier = identifier.substring(1);
        }
        ReferenceType referenceType = QNameConstants.WSSE_FACTORY.createReferenceType();
        referenceType.setURI(identifier);
        String valueType = tokenReference.getWsseValueType();
        if (valueType != null) {
            referenceType.setValueType(valueType);
        }
        JAXBElement<ReferenceType> reference = QNameConstants.WSSE_FACTORY.createReference(referenceType);
        securityTokenReferenceType.getAny().add(reference);
    }
    requestedReferenceType.setSecurityTokenReference(securityTokenReferenceType);
    return requestedReferenceType;
}
Also used : RequestedReferenceType(org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType) KeyIdentifierType(org.apache.cxf.ws.security.sts.provider.model.secext.KeyIdentifierType) SecurityTokenReferenceType(org.apache.cxf.ws.security.sts.provider.model.secext.SecurityTokenReferenceType) JAXBElement(javax.xml.bind.JAXBElement) SecurityTokenReferenceType(org.apache.cxf.ws.security.sts.provider.model.secext.SecurityTokenReferenceType) RequestedReferenceType(org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType) ReferenceType(org.apache.cxf.ws.security.sts.provider.model.secext.ReferenceType)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)1 RequestedReferenceType (org.apache.cxf.ws.security.sts.provider.model.RequestedReferenceType)1 KeyIdentifierType (org.apache.cxf.ws.security.sts.provider.model.secext.KeyIdentifierType)1 ReferenceType (org.apache.cxf.ws.security.sts.provider.model.secext.ReferenceType)1 SecurityTokenReferenceType (org.apache.cxf.ws.security.sts.provider.model.secext.SecurityTokenReferenceType)1