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.extended.pwdModify;
21  
22  
23  import org.apache.directory.api.ldap.model.message.AbstractExtendedRequest;
24  import org.apache.directory.api.util.Strings;
25  
26  
27  /**
28   * The RFC 3062 PwdModify request :
29   * 
30   * <pre>
31   *   PasswdModifyRequestValue ::= SEQUENCE {
32   *    userIdentity    [0]  OCTET STRING OPTIONAL
33   *    oldPasswd       [1]  OCTET STRING OPTIONAL
34   *    newPasswd       [2]  OCTET STRING OPTIONAL }
35   * </pre>
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class PasswordModifyRequestImpl extends AbstractExtendedRequest implements PasswordModifyRequest
40  {
41      /** The user identity */
42      private byte[] userIdentity;
43  
44      /** The previous password */
45      private byte[] oldPassword;
46  
47      /** The new password */
48      private byte[] newPassword;
49  
50  
51      /**
52       * Create a new instance of the PwdModifyRequest extended operation
53       */
54      public PasswordModifyRequestImpl()
55      {
56          setRequestName( EXTENSION_OID );
57      }
58  
59  
60      /**
61       * Create a new instance of the PwdModifyRequest extended operation
62       * 
63       * @param messageId The message ID
64       */
65      public PasswordModifyRequestImpl( int messageId )
66      {
67          super( messageId );
68          setRequestName( EXTENSION_OID );
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public byte[] getUserIdentity()
77      {
78          return userIdentity;
79      }
80  
81  
82      /**
83       * @param userIdentity the userIdentity to set
84       */
85      @Override
86      public void setUserIdentity( byte[] userIdentity )
87      {
88          this.userIdentity = userIdentity;
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public byte[] getOldPassword()
97      {
98          return oldPassword;
99      }
100 
101 
102     /**
103      * @param oldPassword the oldPassword to set
104      */
105     @Override
106     public void setOldPassword( byte[] oldPassword )
107     {
108         this.oldPassword = oldPassword;
109     }
110 
111 
112     /**
113      * {@inheritDoc}
114      */
115     @Override
116     public byte[] getNewPassword()
117     {
118         return newPassword;
119     }
120 
121 
122     /**
123      * @param newPassword the newPassword to set
124      */
125     @Override
126     public void setNewPassword( byte[] newPassword )
127     {
128         this.newPassword = newPassword;
129     }
130 
131 
132     /**
133      * {@inheritDoc}
134      */
135     @Override
136     public PasswordModifyResponse getResultResponse()
137     {
138         if ( getResponse() == null )
139         {
140             setResponse( new PasswordModifyResponseImpl( getMessageId() ) );
141         }
142 
143         return ( PasswordModifyResponse ) getResponse();
144     }
145 
146 
147     /**
148      * @see Object#toString()
149      */
150     @Override
151     public String toString()
152     {
153         StringBuilder sb = new StringBuilder();
154 
155         sb.append( "PwdModifyRequest :" );
156         sb.append( "\n    UserIdentity : " );
157 
158         if ( userIdentity != null )
159         {
160             sb.append( Strings.utf8ToString( userIdentity ) );
161         }
162         else
163         {
164             sb.append( "null" );
165         }
166 
167         sb.append( "\n    oldPassword : " );
168 
169         if ( oldPassword != null )
170         {
171             sb.append( Strings.utf8ToString( oldPassword ) );
172         }
173         else
174         {
175             sb.append( "null" );
176         }
177 
178         sb.append( "\n    newPassword : " );
179 
180         if ( newPassword != null )
181         {
182             sb.append( Strings.utf8ToString( newPassword ) );
183         }
184         else
185         {
186             sb.append( "null" );
187         }
188 
189         return sb.toString();
190     }
191 }