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 */
020
021package org.apache.directory.kerberos.client;
022
023import java.nio.charset.StandardCharsets;
024
025/**
026 * The class to hold the result of change password operation.
027 *
028 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
029 */
030public class ChangePasswordResult
031{
032    /** the result code */
033    private ChangePasswordResultCode code;
034
035    /** result message */
036    private String message;
037
038
039    public ChangePasswordResult( byte[] userData )
040    {
041        // first 2 bytes contain the result code ( from 0-7 )
042        int r = ( userData[0] & 0xFFFF << 8 ) + ( userData[1] & 0xFFFF );
043
044        code = ChangePasswordResultCode.getByValue( r );
045
046        message = new String( userData, 2, userData.length - 2, StandardCharsets.UTF_8 );
047    }
048
049
050    public ChangePasswordResultCode getCode()
051    {
052        return code;
053    }
054
055
056    public String getMessage()
057    {
058        return message;
059    }
060
061
062    @Override
063    public String toString()
064    {
065        return "ChangePasswordResult [result=" + code + ", message=" + message + "]";
066    }
067
068}