1 23 24 package com.sun.enterprise.security.jauth; 25 26 45 46 public class AuthPolicy { 47 48 public static final int SOURCE_AUTH_NONE = 0; 49 public static final int SOURCE_AUTH_SENDER = 1; 50 public static final int SOURCE_AUTH_CONTENT = 2; 51 52 public static final String SENDER = "sender"; 53 public static final String CONTENT = "content"; 54 public static final String BEFORE_CONTENT = "before-content"; 55 public static final String AFTER_CONTENT = "after-content"; 56 57 private int authenticateSource = SOURCE_AUTH_NONE; 58 private boolean authenticateRecipient = false; 59 private boolean recipientBeforeContent = false; 60 61 private void setAuthenticationType(int sourceAuthType) { 62 switch (sourceAuthType) { 63 case SOURCE_AUTH_NONE: 64 case SOURCE_AUTH_SENDER: 65 case SOURCE_AUTH_CONTENT: 66 this.authenticateSource = sourceAuthType; 67 break; 68 default: 69 break; 70 } 71 } 72 73 public AuthPolicy() { } 74 75 public AuthPolicy( int sourceAuthenticationType, 76 boolean authenticateRecipient, boolean beforeContent ) { 77 setAuthenticationType(sourceAuthenticationType); 78 this.authenticateRecipient = authenticateRecipient; 79 this.recipientBeforeContent = beforeContent; 80 } 81 82 public void setSourceAuth(int sourceAuthenticationType) { 83 setAuthenticationType(sourceAuthenticationType); 84 } 85 86 94 public void setContentAuth(boolean required) { 95 if (required) { 96 this.setSourceAuth(SOURCE_AUTH_CONTENT); 97 } 98 else if (!isSenderAuthRequired()) { 99 this.setSourceAuth(SOURCE_AUTH_NONE); 100 } 101 } 102 103 111 public void setSenderAuth(boolean required) { 112 if (required) { 113 this.setSourceAuth(SOURCE_AUTH_SENDER); 114 } 115 else if (!isContentAuthRequired()) { 116 this.setSourceAuth(SOURCE_AUTH_NONE); 117 } 118 } 119 120 public void setRecipientAuth(boolean required, boolean beforeContent) { 121 this.authenticateRecipient = required; 122 this.recipientBeforeContent = beforeContent; 123 } 124 125 public int getSourceAuth() { 126 return this.authenticateSource; 127 } 128 129 public boolean authRequired() { 130 return this.isSourceAuthRequired() || this.isRecipientAuthRequired(); 131 } 132 133 public boolean isSourceAuthRequired() { 134 return this.authenticateSource == 0 ? false : true; 135 } 136 137 public boolean isSenderAuthRequired() { 138 return ( this.isSourceAuthRequired() ? 139 ( this.getSourceAuth() == SOURCE_AUTH_SENDER ? 140 true : false ) : false ); 141 } 142 143 public boolean isContentAuthRequired() { 144 return ( this.isSourceAuthRequired() ? 145 ( this.getSourceAuth() == SOURCE_AUTH_CONTENT ? 146 true : false ) : false ); 147 } 148 149 public boolean isRecipientAuthRequired() { 150 return this.authenticateRecipient; 151 } 152 153 154 public boolean isRecipientAuthBeforeContent() { 158 return this.recipientBeforeContent; 159 } 160 161 public boolean isRecipientAuthBeforeContent(boolean orderForValidation) { 167 return (orderForValidation ? 168 !this.recipientBeforeContent : this.recipientBeforeContent); 169 } 170 171 public String toString() { 172 173 StringBuffer sb = new StringBuffer (); 176 switch (authenticateSource) { 177 case SOURCE_AUTH_NONE: 178 sb.append("source-auth-type = SOURCE_AUTH_NONE"); 179 break; 180 case SOURCE_AUTH_SENDER: 181 sb.append("source-auth-type = SOURCE_AUTH_SENDER"); 182 break; 183 case SOURCE_AUTH_CONTENT: 184 sb.append("source-auth-type = SOURCE_AUTH_CONTENT"); 185 break; 186 } 187 188 if (authenticateRecipient) { 189 sb.append("\n\tauthenticate-recipient=true" + 190 "\n\tbeforeContent=" + recipientBeforeContent); 191 } else { 192 sb.append("\n\tauthenticate-recipient=false"); 193 } 194 return sb.toString(); 195 } 196 197 public boolean equals(Object o) { 198 if (this == o) { 199 return true; 200 } 201 202 if (!(o instanceof AuthPolicy)) { 203 return false; 204 } 205 206 AuthPolicy that = (AuthPolicy)o; 207 if (this.authenticateSource == that.authenticateSource && 208 this.authenticateRecipient == that.authenticateRecipient && 209 this.recipientBeforeContent == that.recipientBeforeContent) { 210 return true; 211 } 212 213 return false; 214 } 215 216 public int hashCode() { 217 return authenticateSource + 218 (authenticateRecipient ? 5 : 0) + 219 (recipientBeforeContent ? 10 : 0); 220 } 221 } 222 | Popular Tags |