Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 57068 invoked from network); 13 Jul 2010 18:41:00 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Jul 2010 18:41:00 -0000 Received: (qmail 14948 invoked by uid 500); 13 Jul 2010 18:41:00 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 14910 invoked by uid 500); 13 Jul 2010 18:41:00 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 14903 invoked by uid 99); 13 Jul 2010 18:41:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 18:41:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 18:40:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 07FA823889B3; Tue, 13 Jul 2010 18:40:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r963810 - /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java Date: Tue, 13 Jul 2010 18:40:03 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100713184004.07FA823889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Tue Jul 13 18:40:03 2010 New Revision: 963810 URL: http://svn.apache.org/viewvc?rev=963810&view=rev Log: o a class to hold the data of historical passwords of a entry Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java?rev=963810&view=auto ============================================================================== --- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java (added) +++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/PasswordHistory.java Tue Jul 13 18:40:03 2010 @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.server.core.authn; + + +import org.apache.directory.shared.ldap.constants.SchemaConstants; +import org.apache.directory.shared.ldap.util.Base64; +import org.apache.directory.shared.ldap.util.DateUtils; +import org.apache.directory.shared.ldap.util.StringTools; + + +/** + * A class to hold the data of historical passwords of a entry. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class PasswordHistory implements Comparable +{ + /** time when password was last changed */ + private String time; + + /** the syntax OID that is to be used on the password data */ + private String syntaxOID = SchemaConstants.OCTET_STRING_SYNTAX; + + /** the length of the password data */ + private int length; + + /** password octet string */ + private String data; + + private static final char DELIMITER = '#'; + + + public PasswordHistory( String pwdHistoryVal ) + { + int pos = pwdHistoryVal.indexOf( DELIMITER ); + time = pwdHistoryVal.substring( 0, pos ); + + pos++; + int nextPos = pwdHistoryVal.indexOf( DELIMITER, pos ); + syntaxOID = pwdHistoryVal.substring( pos, nextPos ); + + nextPos++; + pos = pwdHistoryVal.indexOf( DELIMITER, nextPos ); + length = Integer.parseInt( pwdHistoryVal.substring( nextPos, pos ) ); + + data = pwdHistoryVal.substring( pos + 1 ); + } + + + public PasswordHistory( String time, byte[] password ) + { + this.time = time; + this.data = String.valueOf( Base64.encode( password ) ); + this.length = data.length(); + } + + + public byte[] getHistoryValue() + { + StringBuilder sb = new StringBuilder(); + + sb.append( time ).append( DELIMITER ); + + sb.append( syntaxOID ).append( DELIMITER ); + + sb.append( length ).append( DELIMITER ); + + sb.append( data ); + + return StringTools.getBytesUtf8( sb.toString() ); + } + + + public String getTime() + { + return time; + } + + + public String getSyntaxOID() + { + return syntaxOID; + } + + + public int getLength() + { + return length; + } + + + public byte[] getPassword() + { + return Base64.decode( data.toCharArray() ); + } + + + public int compareTo( PasswordHistory o ) + { + return o.getTime().compareTo( time ); + } + + + @Override + public boolean equals( Object o ) + { + if ( !( o instanceof PasswordHistory ) ) + { + return false; + } + + PasswordHistory other = ( PasswordHistory ) o; + + return this.getTime().equals( other.getTime() ); + } + + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ( ( data == null ) ? 0 : data.hashCode() ); + result = prime * result + length; + result = prime * result + ( ( syntaxOID == null ) ? 0 : syntaxOID.hashCode() ); + result = prime * result + ( ( time == null ) ? 0 : time.hashCode() ); + return result; + } + + + @Override + public String toString() + { + return "PasswordHistory [time=" + time + ", syntaxOID=" + syntaxOID + ", length=" + length + ", data=" + data + + "]"; + } + + public static void main( String[] args ) + { + byte[] pwdhBytes = new PasswordHistory( DateUtils.getGeneralizedTime(), "secret".getBytes() ).getHistoryValue(); + PasswordHistory pwdHistory = new PasswordHistory( StringTools.utf8ToString( pwdhBytes ) ); + System.out.println( pwdHistory ); + } +}