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 */
020package org.apache.directory.shared.ldap.model.exception;
021
022
023import org.apache.directory.shared.i18n.I18n;
024import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
025
026
027/**
028 * A subclass of the {@link LdapOperationException} carrying along
029 * an unequivocal ResultCodeEnum value.
030 * 
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public class LdapAuthenticationNotSupportedException extends LdapOperationException
034{
035    /** The serial version UUID */
036    static final long serialVersionUID = 1L;
037
038    /**
039     * Creates a new instance of LdapAuthenticationNotSupportedException.
040     *
041     * @param resultCode the ResultCodeEnum for this exception
042     * @param message The exception message
043     */
044    public LdapAuthenticationNotSupportedException( ResultCodeEnum resultCode, String message )
045    {
046        super( message );
047        checkResultCode( resultCode );
048        this.resultCode = resultCode;
049    }
050
051
052    /**
053     * Creates a new instance of LdapAuthenticationNotSupportedException.
054     * 
055     * @param resultCode the ResultCodeEnum for this exception
056     */
057    public LdapAuthenticationNotSupportedException( ResultCodeEnum resultCode )
058    {
059        super( null );
060        checkResultCode( resultCode );
061        this.resultCode = resultCode;
062    }
063
064
065    /**
066     * Checks to make sure the resultCode value is right for this exception
067     * type.
068     * 
069     * @throws IllegalArgumentException
070     *             if the result code is not one of
071     *             {@link ResultCodeEnum#INAPPROPRIATEAUTHENTICATION},
072     *             {@link ResultCodeEnum#AUTHMETHODNOTSUPPORTED},
073     *             {@link ResultCodeEnum#CONFIDENTIALITYREQUIRED}.
074     */
075    private void checkResultCode( ResultCodeEnum resultCode )
076    {
077        switch ( resultCode )
078        {
079            case INAPPROPRIATE_AUTHENTICATION :
080            case CONFIDENTIALITY_REQUIRED :
081            case AUTH_METHOD_NOT_SUPPORTED :
082                return;
083                
084            default:
085                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE, resultCode ) );
086        }
087    }
088}