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