yoavs 2004/10/27 09:38:42
Modified: catalina/src/share/org/apache/catalina/realm RealmBase.java
webapps/docs/config realm.xml
Log:
Added doc and better exception handling to Bugzilla 31592 impl.
Revision Changes Path
1.43 +40 -6
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java
Index: RealmBase.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- RealmBase.java 27 Oct 2004 15:56:57 -0000 1.42
+++ RealmBase.java 27 Oct 2004 16:38:41 -0000 1.43
@@ -21,6 +21,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
@@ -337,8 +338,22 @@
return null;
String serverDigestValue = md5a1 + ":" + nOnce + ":" + nc + ":"
+ cnonce + ":" + qop + ":" + md5a2;
+
+ byte[] valueBytes = null;
+ if(getDigestEncoding() == null) {
+ valueBytes = serverDigestValue.getBytes();
+ } else {
+ try {
+ valueBytes = serverDigestValue.getBytes(getDigestEncoding());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
+ throw new IllegalArgumentException(uee.getMessage());
+ }
+ }
+
String serverDigest =
- md5Encoder.encode(md5Helper.digest(serverDigestValue.getBytes()));
+ md5Encoder.encode(md5Helper.digest(valueBytes));
+
if (log.isDebugEnabled()) {
log.debug("Digest : " + clientDigest + " Username:" + username
+ " ClientSigest:" + clientDigest + " nOnce:" + nOnce
@@ -1022,7 +1037,12 @@
if(getDigestEncoding() == null) {
bytes = credentials.getBytes();
} else {
- bytes = credentials.getBytes(getDigestEncoding());
+ try {
+ bytes = credentials.getBytes(getDigestEncoding());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(),
uee);
+ throw new IllegalArgumentException(uee.getMessage());
+ }
}
md.update(bytes);
@@ -1047,8 +1067,8 @@
try {
md5Helper = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- throw new IllegalStateException();
+ log.error("Couldn't get MD5 digest: ", e);
+ throw new IllegalStateException(e.getMessage());
}
}
@@ -1059,8 +1079,22 @@
String digestValue = username + ":" + realmName + ":"
+ getPassword(username);
+
+ byte[] valueBytes = null;
+ if(getDigestEncoding() == null) {
+ valueBytes = digestValue.getBytes();
+ } else {
+ try {
+ valueBytes = digestValue.getBytes(getDigestEncoding());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
+ throw new IllegalArgumentException(uee.getMessage());
+ }
+ }
+
byte[] digest =
- md5Helper.digest(digestValue.getBytes());
+ md5Helper.digest(valueBytes);
+
return md5Encoder.encode(digest);
}
1.7 +5 -0 jakarta-tomcat-catalina/webapps/docs/config/realm.xml
Index: realm.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/config/realm.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- realm.xml 10 Oct 2004 20:43:49 -0000 1.6
+++ realm.xml 27 Oct 2004 16:38:42 -0000 1.7
@@ -111,6 +111,11 @@
to encode user passwords stored in the database. If not specified,
user passwords are assumed to be stored in clear-text.</p>
</attribute>
+
+ <attribute name="digestEncoding" required="false">
+ <p>The charset for encoding digests. If not specified, the platform
+ default will be used.</p>
+ </attribute>
<attribute name="driverName" required="true">
<p>Fully qualified Java class name of the JDBC driver to be
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]