mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
04.17.2009 859bdd9b3b404bc61bb4f6cf02eda18f75a26c7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package org.opends.sdk.extensions;
 
 
 
import java.io.IOException;
 
import org.opends.sdk.ResultCode;
import org.opends.sdk.asn1.ASN1;
import org.opends.sdk.asn1.ASN1Writer;
import org.opends.sdk.responses.AbstractExtendedResult;
import org.opends.sdk.util.ByteString;
import org.opends.sdk.util.ByteStringBuilder;
 
 
 
/**
 * This class implements the password modify extended operation response
 * defined in RFC 3062. It includes support for requiring the user's
 * current password as well as for generating a new password if none was
 * provided.
 */
public class PasswordModifyResult extends
    AbstractExtendedResult<PasswordModifyResult>
{
  private ByteString genPassword;
 
 
 
  public PasswordModifyResult(ResultCode resultCode)
  {
    super(resultCode);
  }
 
 
 
  /**
   * Get the newly generated password.
   * 
   * @return The password generated by the server or <code>null</code>
   *         if it is not available.
   */
  public ByteString getGenPassword()
  {
    return genPassword;
  }
 
 
 
  public PasswordModifyResult setGenPassword(ByteString genPassword)
  {
    this.genPassword = genPassword;
    return this;
  }
 
 
 
  public ByteString getResponseValue()
  {
    if (genPassword != null)
    {
      ByteStringBuilder buffer = new ByteStringBuilder();
      ASN1Writer writer = ASN1.getWriter(buffer);
 
      try
      {
        writer.writeStartSequence();
        writer
            .writeOctetString(
                PasswordModifyRequest.TYPE_PASSWORD_MODIFY_GENERATED_PASSWORD,
                genPassword);
        writer.writeEndSequence();
      }
      catch (IOException ioe)
      {
        // This should never happen unless there is a bug somewhere.
        throw new RuntimeException(ioe);
      }
 
      return buffer.toByteString();
    }
    return null;
  }
 
 
 
  @Override
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    builder.append("PasswordModifyExtendedResponse(resultCode=");
    builder.append(getResultCode());
    builder.append(", matchedDN=");
    builder.append(getMatchedDN());
    builder.append(", diagnosticMessage=");
    builder.append(getDiagnosticMessage());
    builder.append(", referrals=");
    builder.append(getReferralURIs());
    if (genPassword != null)
    {
      builder.append(", genPassword=");
      builder.append(genPassword);
    }
    builder.append(", controls=");
    builder.append(getControls());
    builder.append(")");
    return builder.toString();
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public String getResponseName()
  {
    // No response name defined.
    return null;
  }
}