001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.extras.extended.pwdModify; 021 022 023import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl; 024import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 025import org.apache.directory.api.util.Strings; 026 027 028/** 029 * The RFC 3062 PwdModify response : 030 * 031 * <pre> 032 * PasswdModifyResponseValue ::= SEQUENCE { 033 * genPasswd [0] OCTET STRING OPTIONAL } 034 * </pre> 035 * 036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 037 */ 038public class PasswordModifyResponseImpl extends ExtendedResponseImpl implements PasswordModifyResponse 039{ 040 /** The generated password */ 041 private byte[] genPassword; 042 043 044 /** 045 * Create a new instance for the PwdModify response 046 * @param messageId The Message ID 047 * @param rcode The result code 048 * @param diagnosticMessage The diagnostic message 049 */ 050 public PasswordModifyResponseImpl( int messageId, ResultCodeEnum rcode, String diagnosticMessage ) 051 { 052 super( messageId, EXTENSION_OID ); 053 054 super.getLdapResult().setMatchedDn( null ); 055 super.getLdapResult().setResultCode( rcode ); 056 super.getLdapResult().setDiagnosticMessage( diagnosticMessage ); 057 } 058 059 060 /** 061 * Create a new instance for the PwdModify response 062 * @param messageId The Message ID 063 * @param rcode The result code 064 */ 065 public PasswordModifyResponseImpl( int messageId, ResultCodeEnum rcode ) 066 { 067 super( messageId, EXTENSION_OID ); 068 069 super.getLdapResult().setMatchedDn( null ); 070 super.getLdapResult().setResultCode( rcode ); 071 } 072 073 074 /** 075 * Instantiates a new password Modify response. 076 * 077 * @param messageId the message id 078 */ 079 public PasswordModifyResponseImpl( int messageId ) 080 { 081 super( messageId, EXTENSION_OID ); 082 super.getLdapResult().setMatchedDn( null ); 083 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); 084 } 085 086 087 /** 088 * Instantiates a new password Modify response. 089 */ 090 public PasswordModifyResponseImpl() 091 { 092 super( EXTENSION_OID ); 093 super.getLdapResult().setMatchedDn( null ); 094 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); 095 } 096 097 098 /** 099 * {@inheritDoc} 100 */ 101 @Override 102 public byte[] getGenPassword() 103 { 104 return genPassword; 105 } 106 107 108 /** 109 * Set the generated Password 110 * @param genPassword The generated password 111 */ 112 public void setGenPassword( byte[] genPassword ) 113 { 114 this.genPassword = genPassword; 115 } 116 117 118 /** 119 * @see Object#toString() 120 */ 121 @Override 122 public String toString() 123 { 124 StringBuilder sb = new StringBuilder(); 125 126 sb.append( "PwdModifyResponse :" ); 127 sb.append( "\n genPassword : " ); 128 129 if ( genPassword != null ) 130 { 131 sb.append( Strings.utf8ToString( genPassword ) ); 132 } 133 else 134 { 135 sb.append( "null" ); 136 } 137 138 return sb.toString(); 139 } 140}