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.ExtendedResponseImpl;
24  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
25  import org.apache.directory.api.util.Strings;
26  
27  
28  /**
29   * The RFC 3062 PwdModify response :
30   * 
31   * <pre>
32   * PasswdModifyResponseValue ::= SEQUENCE {
33   *    genPasswd       [0]     OCTET STRING OPTIONAL }
34   * </pre>
35   * 
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class PasswordModifyResponseImpl extends ExtendedResponseImpl implements PasswordModifyResponse
39  {
40      /** The generated password */
41      private byte[] genPassword;
42  
43      
44      /**
45       * Create a new instance for the PwdModify response
46       * @param messageId The Message ID
47       * @param rcode The result code
48       * @param diagnosticMessage The diagnostic message
49       */
50      public PasswordModifyResponseImpl( int messageId, ResultCodeEnum rcode, String diagnosticMessage )
51      {
52          super( messageId, EXTENSION_OID );
53  
54          super.getLdapResult().setMatchedDn( null );
55          super.getLdapResult().setResultCode( rcode );
56          super.getLdapResult().setDiagnosticMessage( diagnosticMessage );
57      }
58  
59  
60      /**
61       * Create a new instance for the PwdModify response
62       * @param messageId The Message ID
63       * @param rcode The result code
64       */
65      public PasswordModifyResponseImpl( int messageId, ResultCodeEnum rcode )
66      {
67          super( messageId, EXTENSION_OID );
68  
69          super.getLdapResult().setMatchedDn( null );
70          super.getLdapResult().setResultCode( rcode );
71      }
72  
73  
74      /**
75       * Instantiates a new password Modify response.
76       *
77       * @param messageId the message id
78       */
79      public PasswordModifyResponseImpl( int messageId )
80      {
81          super( messageId, EXTENSION_OID );
82          super.getLdapResult().setMatchedDn( null );
83          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
84      }
85  
86  
87      /**
88       * Instantiates a new password Modify response.
89       */
90      public PasswordModifyResponseImpl()
91      {
92          super( EXTENSION_OID );
93          super.getLdapResult().setMatchedDn( null );
94          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
95      }
96  
97  
98      /**
99       * {@inheritDoc}
100      */
101     public byte[] getGenPassword()
102     {
103         return genPassword;
104     }
105 
106 
107     /**
108      * Set the generated Password
109      * @param genPassword The generated password
110      */
111     public void setGenPassword( byte[] genPassword )
112     {
113         this.genPassword = genPassword;
114     }
115 
116 
117     /**
118      * @see Object#toString()
119      */
120     public String toString()
121     {
122         StringBuilder sb = new StringBuilder();
123 
124         sb.append( "PwdModifyResponse :" );
125         sb.append( "\n    genPassword : " );
126 
127         if ( genPassword != null )
128         {
129             sb.append( Strings.utf8ToString( genPassword ) );
130         }
131         else
132         {
133             sb.append( "null" );
134         }
135 
136         return sb.toString();
137     }
138 }