Search in sources :

Example 1 with TargetPolicy

use of javax.security.auth.message.MessagePolicy.TargetPolicy in project Payara by payara.

the class AuthMessagePolicy method getMessagePolicy.

public static MessagePolicy getMessagePolicy(String authSource, String authRecipient, boolean mandatory) {
    boolean sourceSender = SENDER.equals(authSource);
    boolean sourceContent = CONTENT.equals(authSource);
    boolean recipientAuth = authRecipient != null;
    boolean beforeContent = BEFORE_CONTENT.equals(authRecipient);
    List<TargetPolicy> targetPolicies = new ArrayList<TargetPolicy>();
    if (recipientAuth && beforeContent) {
        targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_RECIPIENT));
        if (sourceSender) {
            targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_SENDER));
        } else if (sourceContent) {
            targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_CONTENT));
        }
    } else {
        if (sourceSender) {
            targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_SENDER));
        } else if (sourceContent) {
            targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_CONTENT));
        }
        if (recipientAuth) {
            targetPolicies.add(new TargetPolicy(null, () -> AUTHENTICATE_RECIPIENT));
        }
    }
    return new MessagePolicy(targetPolicies.toArray(new TargetPolicy[targetPolicies.size()]), mandatory);
}
Also used : MessagePolicy(javax.security.auth.message.MessagePolicy) TargetPolicy(javax.security.auth.message.MessagePolicy.TargetPolicy) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 MessagePolicy (javax.security.auth.message.MessagePolicy)1 TargetPolicy (javax.security.auth.message.MessagePolicy.TargetPolicy)1