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  import org.apache.directory.api.ldap.model.message.Control;
24  
25  
26  /**
27   * A simple {@link PasswordPolicy} {@link Control} implementation.
28   *
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   * @version $Rev$, $Date$
31   */
32  public class PasswordPolicyImpl implements PasswordPolicy
33  {
34      /** The criticality of this {@link Control} */
35      private boolean criticality;
36  
37      /** The password policy response component if this is a response control */
38      private PasswordPolicyResponse response;
39  
40  
41      /**
42       * Creates a new instance of a PasswordPolicy request Control without any
43       * response data associated with it.
44       */
45      public PasswordPolicyImpl()
46      {
47          response = null;
48      }
49  
50  
51      /**
52       * Creates a new instance of a PasswordPolicy request Control without any
53       * response data associated with it.
54       */
55      public PasswordPolicyImpl( boolean hasResponse )
56      {
57          if ( hasResponse )
58          {
59              response = new PasswordPolicyResponseImpl();
60          }
61          else
62          {
63              response = null;
64          }
65      }
66  
67  
68      /**
69       * Creates a new instance of PasswordPolicy response Control with response 
70       * information packaged into the control.
71       */
72      public PasswordPolicyImpl( PasswordPolicyResponse response )
73      {
74          this.response = response;
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      public String getOid()
82      {
83          return PasswordPolicy.OID;
84      }
85  
86  
87      /**
88       * {@inheritDoc}
89       */
90      public boolean isCritical()
91      {
92          return criticality;
93      }
94  
95  
96      /**
97       * {@inheritDoc}
98       */
99      public void setCritical( boolean isCritical )
100     {
101         this.criticality = isCritical;
102     }
103 
104 
105     /**
106      * 
107      * {@inheritDoc}
108      */
109     public void setResponse( PasswordPolicyResponse response )
110     {
111         this.response = response;
112     }
113 
114 
115     /**
116      * {@inheritDoc}
117      */
118     public boolean hasResponse()
119     {
120         return response != null;
121     }
122 
123 
124     /**
125      * 
126      * {@inheritDoc}
127      */
128     public PasswordPolicyResponse setResponse( boolean hasResponse )
129     {
130         PasswordPolicyResponse old = this.response;
131 
132         if ( hasResponse )
133         {
134             this.response = new PasswordPolicyResponseImpl();
135         }
136         else
137         {
138             this.response = null;
139         }
140 
141         return old;
142     }
143 
144 
145     /**
146      * {@inheritDoc}
147      */
148     public PasswordPolicyResponse getResponse()
149     {
150         return response;
151     }
152 }