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      public byte[] getUserIdentity()
76      {
77          return userIdentity;
78      }
79  
80  
81      /**
82       * @param userIdentity the userIdentity to set
83       */
84      public void setUserIdentity( byte[] userIdentity )
85      {
86          this.userIdentity = userIdentity;
87      }
88  
89  
90      /**
91       * {@inheritDoc}
92       */
93      public byte[] getOldPassword()
94      {
95          return oldPassword;
96      }
97  
98  
99      /**
100      * @param oldPassword the oldPassword to set
101      */
102     public void setOldPassword( byte[] oldPassword )
103     {
104         this.oldPassword = oldPassword;
105     }
106 
107 
108     /**
109      * {@inheritDoc}
110      */
111     public byte[] getNewPassword()
112     {
113         return newPassword;
114     }
115 
116 
117     /**
118      * @param newPassword the newPassword to set
119      */
120     public void setNewPassword( byte[] newPassword )
121     {
122         this.newPassword = newPassword;
123     }
124 
125 
126     /**
127      * {@inheritDoc}
128      */
129     @Override
130     public PasswordModifyResponse getResultResponse()
131     {
132         if ( response == null )
133         {
134             response = new PasswordModifyResponseImpl( getMessageId() );
135         }
136 
137         return ( PasswordModifyResponse ) response;
138     }
139 
140 
141     /**
142      * @see Object#toString()
143      */
144     public String toString()
145     {
146         StringBuilder sb = new StringBuilder();
147 
148         sb.append( "PwdModifyRequest :" );
149         sb.append( "\n    UserIdentity : " );
150 
151         if ( userIdentity != null )
152         {
153             sb.append( Strings.utf8ToString( userIdentity ) );
154         }
155         else
156         {
157             sb.append( "null" );
158         }
159 
160         sb.append( "\n    oldPassword : " );
161 
162         if ( oldPassword != null )
163         {
164             sb.append( Strings.utf8ToString( oldPassword ) );
165         }
166         else
167         {
168             sb.append( "null" );
169         }
170 
171         sb.append( "\n    newPassword : " );
172 
173         if ( newPassword != null )
174         {
175             sb.append( Strings.utf8ToString( newPassword ) );
176         }
177         else
178         {
179             sb.append( "null" );
180         }
181 
182         return sb.toString();
183     }
184 }