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.api.ldap.extras.controls.ppolicy;
21  
22  
23  /**
24   * A simple {@link PasswordPolicy} Control implementation.
25   *
26   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27   * @version $Rev$, $Date$
28   */
29  public class PasswordPolicyImpl implements PasswordPolicy
30  {
31      /** The criticality of this {@link Control} */
32      private boolean criticality;
33  
34      /** The password policy response component if this is a response control */
35      private PasswordPolicyResponse response;
36  
37  
38      /**
39       * Creates a new instance of a PasswordPolicy request Control without any
40       * response data associated with it.
41       */
42      public PasswordPolicyImpl()
43      {
44          response = null;
45      }
46  
47  
48      /**
49       * Creates a new instance of a PasswordPolicy request Control without any
50       * response data associated with it.
51       * 
52       * @param hasResponse A flag set to <tt>true</tt> if the control should have a response
53       */
54      public PasswordPolicyImpl( boolean hasResponse )
55      {
56          if ( hasResponse )
57          {
58              response = new PasswordPolicyResponseImpl();
59          }
60          else
61          {
62              response = null;
63          }
64      }
65  
66  
67      /**
68       * Creates a new instance of PasswordPolicy response Control with response 
69       * information packaged into the control.
70       * 
71       * @param response The encapsulated response
72       */
73      public PasswordPolicyImpl( PasswordPolicyResponse response )
74      {
75          this.response = response;
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public String getOid()
84      {
85          return PasswordPolicy.OID;
86      }
87  
88  
89      /**
90       * {@inheritDoc}
91       */
92      @Override
93      public boolean isCritical()
94      {
95          return criticality;
96      }
97  
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public void setCritical( boolean isCritical )
104     {
105         this.criticality = isCritical;
106     }
107 
108 
109     /**
110      * 
111      * {@inheritDoc}
112      */
113     @Override
114     public void setResponse( PasswordPolicyResponse response )
115     {
116         this.response = response;
117     }
118 
119 
120     /**
121      * {@inheritDoc}
122      */
123     @Override
124     public boolean hasResponse()
125     {
126         return response != null;
127     }
128 
129 
130     /**
131      * 
132      * {@inheritDoc}
133      */
134     @Override
135     public PasswordPolicyResponse setResponse( boolean hasResponse )
136     {
137         PasswordPolicyResponse old = this.response;
138 
139         if ( hasResponse )
140         {
141             this.response = new PasswordPolicyResponseImpl();
142         }
143         else
144         {
145             this.response = null;
146         }
147 
148         return old;
149     }
150 
151 
152     /**
153      * {@inheritDoc}
154      */
155     @Override
156     public PasswordPolicyResponse getResponse()
157     {
158         return response;
159     }
160 
161     
162     /**
163      * Get a String representation of a PasswordPolicyImpl
164      * 
165      * @return A BindResponse String
166      */
167     @Override
168     public String toString()
169     {
170         StringBuilder sb = new StringBuilder();
171 
172         sb.append( "    PasswordPolicy[" );
173         sb.append( "criticality:" ).append( criticality ).append( "] " );
174 
175         if ( response != null )
176         {
177             sb.append( response );
178         }
179         else
180         {
181             sb.append( '\n' );
182         }
183 
184         return sb.toString();
185     }
186 }