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.ldap.client.template.exception;
021
022
023import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyErrorEnum;
024import org.apache.directory.api.ldap.model.exception.LdapException;
025import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
026
027
028/**
029 * Thrown when an attempt to bind or modify a userPassword fails when using
030 * LdapConnectionTemplate.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class PasswordException extends Exception
035{
036    private static final long serialVersionUID = -1185823188085178776L;
037
038    private LdapException ldapException;
039    private ResultCodeEnum resultCode;
040    private PasswordPolicyErrorEnum passwordPolicyError;
041
042
043    /**
044     * Creates a new PasswordException instance
045     */
046    public PasswordException()
047    {
048        super();
049    }
050
051
052    /**
053     * If an LdapException was thrown causing this exception, that 
054     * LdapException is returned.  Otherwise null is returned.
055     *
056     * @return The LdapException that was thrown, or null.
057     */
058    public LdapException getLdapException()
059    {
060        return ldapException;
061    }
062
063
064    /**
065     * Returns the result code from the attempt to bind or modify the 
066     * userPassword.
067     *
068     * @return The result code.
069     */
070    public ResultCodeEnum getResultCode()
071    {
072        return resultCode;
073    }
074
075
076    /**
077     * Returns the password policy error code if present, otherwise null.
078     *
079     * @return The password policy error code or null.
080     */
081    public PasswordPolicyErrorEnum getPasswordPolicyError()
082    {
083        return passwordPolicyError;
084    }
085
086
087    /**
088     * Sets the wrapped exception
089     * 
090     * @param ldapException The wrapped exception
091     * @return The wrapping exception
092     */
093    public PasswordException setLdapException( LdapException ldapException )
094    {
095        this.ldapException = ldapException;
096        
097        return this;
098    }
099
100
101    /**
102     * Set the Password Policy error
103     * 
104     * @param passwordPolicyError The Password Policy error
105     * @return The wrapping exception
106     */
107    public PasswordException setPasswordPolicyError( PasswordPolicyErrorEnum passwordPolicyError )
108    {
109        this.passwordPolicyError = passwordPolicyError;
110        
111        return this;
112    }
113
114
115    /**
116     * Sets the LDAP Result code
117     * 
118     * @param resultCode The LDAP error code
119     * @return The wrapping exception
120     */
121    public PasswordException setResultCode( ResultCodeEnum resultCode )
122    {
123        this.resultCode = resultCode;
124        
125        return this;
126    }
127}