Java Code Examples for org.apache.neethi.Policy#normalize()

The following examples show how to use org.apache.neethi.Policy#normalize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportBinding.java    From steady with Apache License 2.0 6 votes vote down vote up
public Policy getPolicy() {
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();
    if (transportToken != null) {
        all.addPolicyComponent(transportToken);
    }
    if (isIncludeTimestamp()) {
        all.addPolicyComponent(new PrimitiveAssertion(SP12Constants.INCLUDE_TIMESTAMP));
    }
    if (getLayout() != null) {
        all.addPolicyComponent(getLayout());
    }
    ea.addPolicyComponent(all);
    Policy pc = p.normalize(builder.getPolicyRegistry(), true);
    if (pc != null) {
        return pc;
    } else {
        return new Policy();
    }
}
 
Example 2
Source File: InitiatorTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    InitiatorToken initiatorToken = new InitiatorToken(consts, builder);
    initiatorToken.setOptional(PolicyConstants.isOptional(element));
    initiatorToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), initiatorToken);
        break; // TODO process all the token that must be set ..
    }

    return initiatorToken;
}
 
Example 3
Source File: RecipientSignatureTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RecipientSignatureToken recipientSignatureToken = new RecipientSignatureToken(consts, builder);
    recipientSignatureToken.setOptional(PolicyConstants.isOptional(element));
    recipientSignatureToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), recipientSignatureToken);
        break; // TODO process all the token that must be set ..
    }

    return recipientSignatureToken;
}
 
Example 4
Source File: TokenWrapper.java    From steady with Apache License 2.0 6 votes vote down vote up
public Policy getPolicy() {
    if (token != null) {
        Policy p = new Policy();
        ExactlyOne ea = new ExactlyOne();
        p.addPolicyComponent(ea);
        All all = new All();
        all.addPolicyComponent(token);
        ea.addPolicyComponent(all);
        Policy pc = p.normalize(builder.getPolicyRegistry(), true);
        if (pc != null) {
            return pc;
        } else {
            return new Policy();
        }
    }
    return null;
}
 
Example 5
Source File: InitiatorEncryptionTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    InitiatorEncryptionToken initiatorToken = new InitiatorEncryptionToken(consts, builder);
    initiatorToken.setOptional(PolicyConstants.isOptional(element));
    initiatorToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), initiatorToken);
        break; // TODO process all the token that must be set ..
    }

    return initiatorToken;
}
 
Example 6
Source File: InitiatorEncryptionTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    InitiatorEncryptionToken initiatorToken = new InitiatorEncryptionToken(consts, builder);
    initiatorToken.setOptional(PolicyConstants.isOptional(element));
    initiatorToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), initiatorToken);
        break; // TODO process all the token that must be set ..
    }

    return initiatorToken;
}
 
Example 7
Source File: InitiatorSignatureTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    InitiatorSignatureToken initiatorToken = new InitiatorSignatureToken(consts, builder);
    initiatorToken.setOptional(PolicyConstants.isOptional(element));
    initiatorToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), initiatorToken);
        break; // TODO process all the token that must be set ..
    }

    return initiatorToken;
}
 
Example 8
Source File: RecipientEncryptionTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RecipientEncryptionToken recipientEncryptionToken = new RecipientEncryptionToken(consts, builder);
    recipientEncryptionToken.setOptional(PolicyConstants.isOptional(element));
    recipientEncryptionToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), recipientEncryptionToken);
        break; // TODO process all the token that must be set ..
    }

    return recipientEncryptionToken;
}
 
Example 9
Source File: InitiatorSignatureTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    InitiatorSignatureToken initiatorToken = new InitiatorSignatureToken(consts, builder);
    initiatorToken.setOptional(PolicyConstants.isOptional(element));
    initiatorToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), initiatorToken);
        break; // TODO process all the token that must be set ..
    }

    return initiatorToken;
}
 
Example 10
Source File: RecipientEncryptionTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    RecipientEncryptionToken recipientEncryptionToken = new RecipientEncryptionToken(consts, builder);
    recipientEncryptionToken.setOptional(PolicyConstants.isOptional(element));
    recipientEncryptionToken.setIgnorable(PolicyConstants.isIgnorable(element));

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), recipientEncryptionToken);
        break; // TODO process all the token that must be set ..
    }

    return recipientEncryptionToken;
}
 
Example 11
Source File: RecipientTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;


    RecipientToken recipientToken = new RecipientToken(consts, builder);

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), recipientToken);

        /*
         * for the moment we will pick the first token specified in the policy
         */
        break;
    }

    return recipientToken;
}
 
Example 12
Source File: RecipientTokenBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;


    RecipientToken recipientToken = new RecipientToken(consts, builder);

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), recipientToken);

        /*
         * for the moment we will pick the first token specified in the policy
         */
        break;
    }

    return recipientToken;
}
 
Example 13
Source File: AsymmetricBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {

    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    AsymmetricBinding asymmetricBinding = new AsymmetricBinding(consts, builder);

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    Iterator<List<Assertion>> iterator = policy.getAlternatives();
    if (!iterator.hasNext()) {
        throw new IllegalArgumentException(
            "sp:AsymmetricBinding must specify at least one alternative"
        );
    }
    processAlternative(iterator.next(), asymmetricBinding, consts);

    return asymmetricBinding;
}
 
Example 14
Source File: SymmetricBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    SymmetricBinding symmetricBinding = new SymmetricBinding(consts, builder);

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    Iterator<List<Assertion>> iterator = policy.getAlternatives();
    if (!iterator.hasNext()) {
        throw new IllegalArgumentException(
            "sp:SymmetricBinding must specify at least one alternative"
        );
    }
    processAlternatives(iterator.next(), symmetricBinding, consts);

    return symmetricBinding;
}
 
Example 15
Source File: SupportingTokensBuilder.java    From steady with Apache License 2.0 5 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP11Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                                              SP11Constants.INSTANCE,
                                              builder);
    } else if (SP11Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING,
                                              SP11Constants.INSTANCE,
                                              builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative
         */
        break;
    }

    return supportingToken;
}
 
Example 16
Source File: SymmetricBinding.java    From steady with Apache License 2.0 5 votes vote down vote up
public Policy getPolicy() {
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();
    
    if (this.getProtectionToken() != null) {
        all.addPolicyComponent(this.getProtectionToken());
    }
    if (this.getSignatureToken() != null) {
        all.addPolicyComponent(this.getSignatureToken());
    }
    if (this.getEncryptionToken() != null) {
        all.addPolicyComponent(this.getEncryptionToken());
    }
    if (isIncludeTimestamp()) {
        all.addPolicyComponent(new PrimitiveAssertion(SP12Constants.INCLUDE_TIMESTAMP));
    }
    if (getLayout() != null) {
        all.addPolicyComponent(getLayout());
    }

    
    ea.addPolicyComponent(all);
    Policy pc = p.normalize(builder.getPolicyRegistry(), true);
    if (pc != null) {
        return pc;
    } else {
        return new Policy();
    }
}
 
Example 17
Source File: SupportingToken.java    From steady with Apache License 2.0 5 votes vote down vote up
public Policy getPolicy() {
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();

    for (Token token : getTokens()) {
        all.addPolicyComponent(token);
    }
    
    if (signedParts != null) {
        all.addPolicyComponent(signedParts);
    } else if (signedElements != null) {
        all.addPolicyComponent(signedElements);
    } else if (encryptedParts != null) {
        all.addPolicyComponent(encryptedParts);
    } else if (encryptedElements != null) {
        all.addPolicyComponent(encryptedElements);
    }        
    
    ea.addPolicyComponent(all);
    Policy pc = p.normalize(builder.getPolicyRegistry(), true);
    if (pc != null) {
        return pc;
    } else {
        return new Policy();
    }
}
 
Example 18
Source File: SupportingTokens12Builder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory) {
    QName name = DOMUtils.getElementQName(element);
    SupportingToken supportingToken = null;

    if (SP12Constants.SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SUPPORTING,
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    } else if (SP12Constants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS.equals(name)) {
        supportingToken = new SupportingToken(
                SupportTokenType.SUPPORTING_TOKEN_SIGNED_ENDORSING_ENCRYPTED, 
                SP12Constants.INSTANCE,
                builder);
    }

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        processAlternative(iterator.next(), supportingToken);
        /*
         * for the moment we will say there should be only one alternative 
         */
        break;            
    }

    return supportingToken;
}
 
Example 19
Source File: TransportTokenBuilder.java    From steady with Apache License 2.0 4 votes vote down vote up
public Assertion build(Element element, AssertionBuilderFactory factory)
    throws IllegalArgumentException {
    
    SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
        ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;

    
    TransportToken transportToken = new TransportToken(consts, builder);

    Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
    policy = policy.normalize(builder.getPolicyRegistry(), false);

    for (Iterator<List<Assertion>> iterator = policy.getAlternatives(); iterator.hasNext();) {
        transportToken.setToken((Token)((iterator.next()).get(0)));
        break; // since there should be only one alternative
    }

    return transportToken;
}
 
Example 20
Source File: AsymmetricBinding.java    From steady with Apache License 2.0 4 votes vote down vote up
public Policy getPolicy() {
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();
    
    /*
    asymmetricBinding.setAlgorithmSuite(algorithmSuite);
    asymmetricBinding.setProtectionOrder(getProtectionOrder());
    asymmetricBinding.setSignatureProtection(isSignatureProtection());
    asymmetricBinding.setSignedEndorsingSupportingTokens(getSignedEndorsingSupportingTokens());
    asymmetricBinding.setTokenProtection(isTokenProtection());
    */
    if (getInitiatorToken() != null) {
        all.addPolicyComponent(getInitiatorToken());
    }
    if (getInitiatorSignatureToken() != null) {
        all.addPolicyComponent(getInitiatorSignatureToken());
    }
    if (getInitiatorEncryptionToken() != null) {
        all.addPolicyComponent(getInitiatorEncryptionToken());
    }
    if (getRecipientToken() != null) {
        all.addPolicyComponent(getRecipientToken());
    }
    if (getRecipientSignatureToken() != null) {
        all.addPolicyComponent(getRecipientSignatureToken());
    }
    if (getRecipientEncryptionToken() != null) {
        all.addPolicyComponent(getRecipientEncryptionToken());
    }
    /*
    if (isEntireHeadersAndBodySignatures()) {
        all.addPolicyComponent(new PrimitiveAssertion(SP12Constants.ONLY_SIGN_ENTIRE_HEADERS_AND_BODY));
    }
    */
    if (isIncludeTimestamp()) {
        all.addPolicyComponent(new PrimitiveAssertion(SP12Constants.INCLUDE_TIMESTAMP));
    }
    if (getLayout() != null) {
        all.addPolicyComponent(getLayout());
    }
    ea.addPolicyComponent(all);
    Policy pc = p.normalize(builder.getPolicyRegistry(), true);
    if (pc != null) {
        return pc;
    } else {
        return new Policy();
    }
}