You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/03/17 07:00:52 UTC

svn commit: r157905 - in directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw: ChangePasswordException.java ChangePasswordService.java exceptions/ exceptions/ChangePasswordException.java exceptions/ErrorType.java service/ChangePasswordServiceImpl.java

Author: erodriguez
Date: Wed Mar 16 22:00:46 2005
New Revision: 157905

URL: http://svn.apache.org/viewcvs?view=rev&rev=157905
Log:
Updated Change Password to use same exception handling style as Kerberos.

Added:
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ChangePasswordException.java
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ErrorType.java
Removed:
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordException.java
Modified:
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordService.java
    directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/service/ChangePasswordServiceImpl.java

Modified: directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordService.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordService.java?view=diff&r1=157904&r2=157905
==============================================================================
--- directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordService.java (original)
+++ directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/ChangePasswordService.java Wed Mar 16 22:00:46 2005
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 
+import org.apache.changepw.exceptions.ChangePasswordException;
 import org.apache.changepw.messages.ChangePasswordReply;
 import org.apache.changepw.messages.ChangePasswordRequest;
 import org.apache.kerberos.exceptions.KerberosException;
@@ -29,6 +30,6 @@
 public interface ChangePasswordService
 {
 	public ChangePasswordReply getReplyFor( ChangePasswordRequest request )
-			throws KerberosException, IOException;
+			throws ChangePasswordException, KerberosException, IOException;
 }
 

Added: directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ChangePasswordException.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ChangePasswordException.java?view=auto&rev=157905
==============================================================================
--- directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ChangePasswordException.java (added)
+++ directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ChangePasswordException.java Wed Mar 16 22:00:46 2005
@@ -0,0 +1,125 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.changepw.exceptions;
+
+/**
+ * The root of the Change Password exception hierarchy.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ChangePasswordException extends Exception
+{
+    /**
+     * The Change Password error code associated with this exception
+     */
+    private final int errorCode;
+    
+    /**
+     * Additional data about the error for use by the application
+     * to help it recover from or handle the error.
+     */
+    private byte[] explanatoryData; 
+    
+    // ------------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Creates a ChangePasswordException with an error code and a message.
+     *
+     * @param errorCode the error code associated with this ChangePasswordException
+     * @param msg the standard Change Password error message for this ChangePasswordException
+     */
+    public ChangePasswordException( int errorCode, String msg )
+    {
+        super( msg );
+
+        this.errorCode = errorCode;
+    }
+
+
+    /**
+     * Creates a ChangePasswordException with an error code, a message and an
+     * underlying throwable that caused this fault.
+     *
+     * @param errorCode the error code associated with this ChangePasswordException
+     * @param msg the standard Change Password error message for this ChangePasswordException
+     * @param cause the underlying failure, if any
+     */
+    public ChangePasswordException( int errorCode, String msg, Throwable cause )
+    {
+        super( msg, cause );
+
+        this.errorCode = errorCode;
+    }
+    
+    
+    /**
+     * Creates a ChangePasswordException with an error code and a message.
+     *
+     * @param errorCode the error code associated with this ChangePasswordException
+     * @param msg the standard Change Password error message for this ChangePasswordException
+     */
+    public ChangePasswordException( ErrorType errorType )
+    {
+        super( errorType.getMessage() );
+
+        this.errorCode = errorType.getOrdinal();
+    }
+    
+    
+    /**
+     * Creates a ChangePasswordException with an error code, a message, and
+     * data helping to explain what caused this fault.
+     *
+     * @param errorCode the error code associated with this ChangePasswordException
+     * @param msg the standard Change Password error message for this ChangePasswordException
+     * @param explanatoryData data helping to explain this fault, if any
+     */
+    public ChangePasswordException( ErrorType errorType, byte[] explanatoryData )
+    {
+        super( errorType.getMessage() );
+
+        this.errorCode = errorType.getOrdinal();
+        this.explanatoryData = explanatoryData;
+    }
+    
+    
+    /**
+     * Gets the protocol error code associated with this ChangePasswordException.
+     *
+     * @return the error code associated with this ChangePasswordException
+     */
+    public int getErrorCode()
+    {
+        return this.errorCode;
+    }
+    
+    /**
+     * Gets the explanatory data associated with this ChangePasswordException.
+     *
+     * @return the explanatory data associated with this ChangePasswordException
+     */
+	public byte[] getExplanatoryData()
+	{
+		return explanatoryData;
+	}
+}
+

Added: directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ErrorType.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ErrorType.java?view=auto&rev=157905
==============================================================================
--- directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ErrorType.java (added)
+++ directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/exceptions/ErrorType.java Wed Mar 16 22:00:46 2005
@@ -0,0 +1,146 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.changepw.exceptions;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Type safe enumeration of Change Password error types
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public final class ErrorType implements Comparable
+{
+	/*
+	 * Enumeration elements are constructed once upon class loading.
+	 * Order of appearance here determines the order of compareTo.
+	 */
+	public static final ErrorType KRB5_KPASSWD_MALFORMED = new ErrorType( 1,
+	    "Request failed due to being malformed." );
+	public static final ErrorType KRB5_KPASSWD_HARDERROR = new ErrorType( 2,
+	    "Request failed due to a hard error in processing the request." );
+	public static final ErrorType KRB5_KPASSWD_AUTHERROR = new ErrorType( 3,
+	    "Request failed due to an error in authentication processing." );
+	public static final ErrorType KRB5_KPASSWD_SOFTERROR = new ErrorType( 4,
+	    "Request failed due to a soft error in processing the request." );
+	public static final ErrorType KRB5_KPASSWD_ACCESSDENIED = new ErrorType( 5,
+	    "Requestor not authorized." );
+	public static final ErrorType KRB5_KPASSWD_BAD_VERSION = new ErrorType( 6,
+	    "Protocol version unsupported." );
+	public static final ErrorType KRB5_KPASSWD_INITIAL_FLAG_NEEDED = new ErrorType( 7,
+	    "Initial flag required." );
+	public static final ErrorType KRB5_KPASSWD_UNKNOWN_ERROR = new ErrorType( 8,
+	    "Request failed for an unknown reason." );
+
+    /** Array for building a List of VALUES. */
+    private static final ErrorType[] values = {
+            KRB5_KPASSWD_MALFORMED,
+            KRB5_KPASSWD_HARDERROR,
+            KRB5_KPASSWD_AUTHERROR,
+            KRB5_KPASSWD_SOFTERROR,
+            KRB5_KPASSWD_ACCESSDENIED,
+            KRB5_KPASSWD_BAD_VERSION,
+            KRB5_KPASSWD_INITIAL_FLAG_NEEDED,
+            KRB5_KPASSWD_UNKNOWN_ERROR
+    };
+
+    /** a list of all the error type constants */
+    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
+
+    /** the name of the error type */
+    private final String name;
+
+    /** the value/code for the error type */
+    private final int ordinal;
+
+
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private ErrorType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+        this.name    = name;
+    }
+
+
+    /**
+     * Returns the message for this Change Password error.
+     *
+     * @return the message for this Change Password error.
+     */
+    public String getMessage()
+    {
+		return name;
+	}
+    
+    /**
+     * Returns the message for this Change Password error.
+     *
+     * @return the message for this Change Password error.
+     */
+    public String toString()
+    {
+		return name;
+	}
+    
+    /**
+     * Compares this type to another object hopefully one that is of the same
+     * type.
+     *
+     * @param that the object to compare this ErrorType to
+     * @return ordinal - ( ( ErrorType ) that ).ordinal;
+     */
+	public int compareTo( Object that )
+    {
+		return ordinal - ( ( ErrorType ) that ).ordinal;
+	}
+	
+    /**
+     * Gets the ordinal by its ordinal value.
+     *
+     * @param ordinal the ordinal value of the ordinal
+     * @return the type corresponding to the ordinal value
+     */
+	public static ErrorType getTypeByOrdinal( int ordinal )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+        {
+			if ( values[ ii ].ordinal == ordinal )
+            {
+				return values[ ii ];
+            }
+        }
+
+		return KRB5_KPASSWD_UNKNOWN_ERROR;
+	}
+	
+    /**
+     * Gets the ordinal value associated with this Change Password error.
+     *
+     * @return the ordinal value associated with this Change Password error
+     */
+	public int getOrdinal()
+    {
+		return ordinal;
+	}
+}
+

Modified: directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/service/ChangePasswordServiceImpl.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/service/ChangePasswordServiceImpl.java?view=diff&r1=157904&r2=157905
==============================================================================
--- directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/service/ChangePasswordServiceImpl.java (original)
+++ directory/protocol-providers/changepw/trunk/core/src/java/org/apache/changepw/service/ChangePasswordServiceImpl.java Wed Mar 16 22:00:46 2005
@@ -23,8 +23,9 @@
 import javax.security.auth.kerberos.KerberosKey;
 import javax.security.auth.kerberos.KerberosPrincipal;
 
-import org.apache.changepw.ChangePasswordException;
 import org.apache.changepw.ChangePasswordService;
+import org.apache.changepw.exceptions.ChangePasswordException;
+import org.apache.changepw.exceptions.ErrorType;
 import org.apache.changepw.io.ChangePasswordDataDecoder;
 import org.apache.changepw.messages.ChangePasswordReply;
 import org.apache.changepw.messages.ChangePasswordReplyModifier;
@@ -72,7 +73,7 @@
 	}
 	
 	public ChangePasswordReply getReplyFor( ChangePasswordRequest request )
-			throws KerberosException, IOException
+			throws ChangePasswordException, KerberosException, IOException
     {
 		ApplicationRequest authHeader = request.getAuthHeader();
 		
@@ -107,7 +108,7 @@
 		catch (KerberosException ke)
 		{
 			ke.printStackTrace();
-			throw ChangePasswordException.KRB5_KPASSWD_AUTHERROR;
+			throw new ChangePasswordException( ErrorType.KRB5_KPASSWD_AUTHERROR );
 		}
 		
 		ChangePasswordData passwordData = null;