001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.exception;
021
022
023 import javax.naming.AuthenticationNotSupportedException;
024
025 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
026
027
028 /**
029 * A subclass of the {@link AuthenticationNotSupportedException} carrying along
030 * an unequivocal ResultCodeEnum value.
031 *
032 * @see <a
033 * href="http://java.sun.com/j2se/1.4.2/docs/guide/jndi/jndi-ldap-gl.html#EXCEPT">
034 * LDAP ResultCode to JNDI Exception Mappings</a>
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev: 613579 $
037 */
038 public class LdapAuthenticationNotSupportedException extends AuthenticationNotSupportedException implements
039 LdapException
040 {
041 static final long serialVersionUID = 2532733848470791678L;
042
043 /** the result code type safe enumeration */
044 private final ResultCodeEnum resultCode;
045
046
047 // ------------------------------------------------------------------------
048 // C O N S T R U C T O R S
049 // ------------------------------------------------------------------------
050
051 /**
052 * Creates an LdapException with the resultCode.
053 *
054 * @see AuthenticationNotSupportedException#AuthenticationNotSupportedException()
055 * @param resultCode
056 * the resultCode enumeration
057 * @throws IllegalArgumentException
058 * if the resultCode is not one of the codes corresponding to an
059 * AuthenticationNotSupportedException
060 */
061 public LdapAuthenticationNotSupportedException(ResultCodeEnum resultCode)
062 {
063 super();
064 this.resultCode = resultCode;
065 checkResultCode();
066 }
067
068
069 /**
070 * Sets the resultCode associated with this LdapException.
071 *
072 * @see AuthenticationNotSupportedException#AuthenticationNotSupportedException(String)
073 * @param resultCode
074 * the resultCode enumeration
075 * @throws IllegalArgumentException
076 * if the resultCode is not one of the codes corresponding to an
077 * AuthenticationNotSupportedException
078 */
079 public LdapAuthenticationNotSupportedException(String explanation, ResultCodeEnum resultCode)
080 {
081 super( explanation );
082 this.resultCode = resultCode;
083 checkResultCode();
084 }
085
086
087 // ------------------------------------------------------------------------
088 // LdapException methods
089 // ------------------------------------------------------------------------
090
091 /**
092 * @see LdapException#getResultCode()
093 */
094 public ResultCodeEnum getResultCode()
095 {
096 return resultCode;
097 }
098
099
100 // ------------------------------------------------------------------------
101 // P R I V A T E M E T H O D S
102 // ------------------------------------------------------------------------
103
104 /**
105 * Checks to make sure the resultCode value is right for this exception
106 * type.
107 *
108 * @throws IllegalArgumentException
109 * if the result code is not one of
110 * {@link ResultCodeEnum#INAPPROPRIATEAUTHENTICATION},
111 * {@link ResultCodeEnum#AUTHMETHODNOTSUPPORTED},
112 * {@link ResultCodeEnum#CONFIDENTIALITYREQUIRED}.
113 */
114 private void checkResultCode()
115 {
116 switch ( resultCode )
117 {
118 case INAPPROPRIATE_AUTHENTICATION :
119 case CONFIDENTIALITY_REQUIRED :
120 case AUTH_METHOD_NOT_SUPPORTED :
121 break;
122
123 default:
124 throw new IllegalArgumentException( "Unexceptable result code " + "for this exception type: "
125 + resultCode );
126 }
127 }
128 }