FileDocCategorySizeDatePackage
AuthPolicy.javaAPI DocGlassfish v2 API9545Fri May 04 22:35:42 BST 2007com.sun.enterprise.security.jauth

AuthPolicy

public class AuthPolicy extends Object

Fields Summary
public static final int
SOURCE_AUTH_NONE
public static final int
SOURCE_AUTH_SENDER
public static final int
SOURCE_AUTH_CONTENT
public static final String
SENDER
public static final String
CONTENT
public static final String
BEFORE_CONTENT
public static final String
AFTER_CONTENT
private int
authenticateSource
private boolean
authenticateRecipient
private boolean
recipientBeforeContent
Constructors Summary
public AuthPolicy()

 
public AuthPolicy(int sourceAuthenticationType, boolean authenticateRecipient, boolean beforeContent)

	setAuthenticationType(sourceAuthenticationType);
	this.authenticateRecipient = authenticateRecipient;
	this.recipientBeforeContent = beforeContent;
    
public AuthPolicy(javax.security.auth.message.MessagePolicy messagePolicy)

        if (messagePolicy != null) {
            TargetPolicy[] targetPolicies = messagePolicy.getTargetPolicies();
            if (targetPolicies != null && targetPolicies.length > 0) {
                int contentInd = -1;
                int recipientInd = -1;
                for (int i = 0; i < targetPolicies.length; i++) {
                     ProtectionPolicy pp =
                             targetPolicies[i].getProtectionPolicy();

                     if (ProtectionPolicy.AUTHENTICATE_RECIPIENT.equals(
                             pp.getID())) {
                         recipientInd = i;   
                         this.authenticateRecipient = true;
                     } else if (ProtectionPolicy.AUTHENTICATE_SENDER.equals(
                             pp.getID())) {
                         setAuthenticationType(SOURCE_AUTH_SENDER);
                     } else if (ProtectionPolicy.AUTHENTICATE_CONTENT.equals(
                             pp.getID())) {
                         contentInd = i;
                         setAuthenticationType(SOURCE_AUTH_CONTENT);
                     }
                }

                if (authenticateRecipient && contentInd >= 0) {
                    this.recipientBeforeContent = (recipientInd < contentInd);
                }
            }
        }
    
Methods Summary
public booleanauthRequired()

	return this.isSourceAuthRequired() || this.isRecipientAuthRequired();
    
public booleanequals(java.lang.Object o)

	if (this == o) {
	    return true;
	}

	if (!(o instanceof AuthPolicy)) {
	    return false;
	}

	AuthPolicy that = (AuthPolicy)o;
	if (this.authenticateSource == that.authenticateSource &&
	    this.authenticateRecipient == that.authenticateRecipient &&
	    this.recipientBeforeContent == that.recipientBeforeContent) {
	    return true;
	}

	return false;
    
public intgetSourceAuth()

	return this.authenticateSource;
    
public inthashCode()

	return authenticateSource +
		(authenticateRecipient ? 5 : 0) +
		(recipientBeforeContent ? 10 : 0);
    
public booleanisContentAuthRequired()

	return ( this.isSourceAuthRequired() ? 
		 ( this.getSourceAuth() == SOURCE_AUTH_CONTENT ? 
		   true : false ) : false );
    
public booleanisRecipientAuthBeforeContent()

 	return this.recipientBeforeContent;
    
public booleanisRecipientAuthBeforeContent(boolean orderForValidation)

 	return (orderForValidation ? 
		!this.recipientBeforeContent : this.recipientBeforeContent);
    
public booleanisRecipientAuthRequired()

	return this.authenticateRecipient;
    
public booleanisSenderAuthRequired()

	return ( this.isSourceAuthRequired() ? 
		 ( this.getSourceAuth() == SOURCE_AUTH_SENDER ? 
		   true : false ) : false );
    
public booleanisSourceAuthRequired()

	return this.authenticateSource == 0 ? false : true;
    
private voidsetAuthenticationType(int sourceAuthType)


        
	switch (sourceAuthType) {
	    case SOURCE_AUTH_NONE:
	    case SOURCE_AUTH_SENDER:
	    case SOURCE_AUTH_CONTENT:
		this.authenticateSource = sourceAuthType;
		break;
	    default:
		break;
	}
    
public voidsetContentAuth(boolean required)

	if (required) {
	    this.setSourceAuth(SOURCE_AUTH_CONTENT);
	}
	else if (!isSenderAuthRequired()) {
	    this.setSourceAuth(SOURCE_AUTH_NONE);
	}
    
public voidsetRecipientAuth(boolean required, boolean beforeContent)

	this.authenticateRecipient = required;
	this.recipientBeforeContent = beforeContent;
    
public voidsetSenderAuth(boolean required)

	if (required) {
	    this.setSourceAuth(SOURCE_AUTH_SENDER);
	}
	else if (!isContentAuthRequired()) {
	    this.setSourceAuth(SOURCE_AUTH_NONE);
	}
    
public voidsetSourceAuth(int sourceAuthenticationType)

	setAuthenticationType(sourceAuthenticationType);
    
public java.lang.StringtoString()


	// wait for 1.5
	// StringBuilder sb = new StringBuilder();
	StringBuffer sb = new StringBuffer();
	switch (authenticateSource) {
	case SOURCE_AUTH_NONE:
	    sb.append("source-auth-type = SOURCE_AUTH_NONE");
	    break;
	case SOURCE_AUTH_SENDER:
	    sb.append("source-auth-type = SOURCE_AUTH_SENDER");
	    break;
	case SOURCE_AUTH_CONTENT:
	    sb.append("source-auth-type = SOURCE_AUTH_CONTENT");
	    break;
	}

	if (authenticateRecipient) {
	    sb.append("\n\tauthenticate-recipient=true" +
			"\n\tbeforeContent=" + recipientBeforeContent);
	} else {
	    sb.append("\n\tauthenticate-recipient=false");
	}
	return sb.toString();