View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.ldap.client.template.exception;
21  
22  
23  import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyErrorEnum;
24  import org.apache.directory.api.ldap.model.exception.LdapException;
25  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26  
27  
28  /**
29   * Thrown when an attempt to bind or modify a userPassword fails when using
30   * LdapConnectionTemplate.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class PasswordException extends Exception
35  {
36      private static final long serialVersionUID = -1185823188085178776L;
37  
38      private LdapException ldapException;
39      private ResultCodeEnum resultCode;
40      private PasswordPolicyErrorEnum passwordPolicyError;
41  
42  
43      /**
44       * Creates a new PasswordException instance
45       */
46      public PasswordException()
47      {
48          super();
49      }
50  
51  
52      /**
53       * If an LdapException was thrown causing this exception, that 
54       * LdapException is returned.  Otherwise null is returned.
55       *
56       * @return The LdapException that was thrown, or null.
57       */
58      public LdapException getLdapException()
59      {
60          return ldapException;
61      }
62  
63  
64      /**
65       * Returns the result code from the attempt to bind or modify the 
66       * userPassword.
67       *
68       * @return The result code.
69       */
70      public ResultCodeEnum getResultCode()
71      {
72          return resultCode;
73      }
74  
75  
76      /**
77       * Returns the password policy error code if present, otherwise null.
78       *
79       * @return The password policy error code or null.
80       */
81      public PasswordPolicyErrorEnum getPasswordPolicyError()
82      {
83          return passwordPolicyError;
84      }
85  
86  
87      /**
88       * Sets the wrapped exception
89       * 
90       * @param ldapException The wrapped exception
91       * @return The wrapping exception
92       */
93      public PasswordException setLdapException( LdapException ldapException )
94      {
95          this.ldapException = ldapException;
96          
97          return this;
98      }
99  
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 }