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   *     https://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       * Creates a new PasswordException instance
53       * 
54       * @param message The message to store
55       */
56      public PasswordException( String message )
57      {
58          super( message );
59      }
60  
61  
62      /**
63       * If an LdapException was thrown causing this exception, that 
64       * LdapException is returned.  Otherwise null is returned.
65       *
66       * @return The LdapException that was thrown, or null.
67       */
68      public LdapException getLdapException()
69      {
70          return ldapException;
71      }
72  
73  
74      /**
75       * Returns the result code from the attempt to bind or modify the 
76       * userPassword.
77       *
78       * @return The result code.
79       */
80      public ResultCodeEnum getResultCode()
81      {
82          return resultCode;
83      }
84  
85  
86      /**
87       * Returns the password policy error code if present, otherwise null.
88       *
89       * @return The password policy error code or null.
90       */
91      public PasswordPolicyErrorEnum getPasswordPolicyError()
92      {
93          return passwordPolicyError;
94      }
95  
96  
97      /**
98       * Sets the wrapped exception
99       * 
100      * @param ldapException The wrapped exception
101      * @return The wrapping exception
102      */
103     public PasswordException setLdapException( LdapException ldapException )
104     {
105         this.ldapException = ldapException;
106         return this;
107     }
108 
109 
110     /**
111      * Set the Password Policy error
112      * 
113      * @param passwordPolicyError The Password Policy error
114      * @return The wrapping exception
115      */
116     public PasswordException setPasswordPolicyError( PasswordPolicyErrorEnum passwordPolicyError )
117     {
118         this.passwordPolicyError = passwordPolicyError;
119         return this;
120     }
121 
122 
123     /**
124      * Sets the LDAP Result code
125      * 
126      * @param resultCode The LDAP error code
127      * @return The wrapping exception
128      */
129     public PasswordException setResultCode( ResultCodeEnum resultCode )
130     {
131         this.resultCode = resultCode;
132         return this;
133     }
134 }