You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tb...@apache.org on 2006/12/12 16:24:14 UTC
svn commit: r486187 [18/49] - in /directory/trunks/triplesec: ./ admin-api/
admin-api/src/ admin-api/src/main/ admin-api/src/main/java/
admin-api/src/main/java/org/ admin-api/src/main/java/org/safehaus/
admin-api/src/main/java/org/safehaus/triplesec/ a...
Added: directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/HotpErrorConstants.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/HotpErrorConstants.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/HotpErrorConstants.java (added)
+++ directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/HotpErrorConstants.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,239 @@
+/*
+ * 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.safehaus.otp;
+
+
+import java.util.Vector;
+
+
+/**
+ * Constants used by hotp.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class HotpErrorConstants
+{
+ /*
+ * Nice to have idea
+ * ------------------
+ * It would be nice to be able to grab a ResourceBundle around a Preferences
+ * node and use that to access these error messages in an internationalized
+ * manner. It would be nice to wrap a ResourceBundle around Preferences in
+ * general.
+ */
+
+ /**
+ * Message prefix for locked out accounts
+ */
+ public static final String PREFIX = "HOTP-";
+
+ /**
+ * Message prefix for locked out accounts
+ */
+ public static final int LOCKEDOUT_VAL = 0;
+
+ /**
+ * Message prefix for locked out accounts
+ */
+ public static final int DISABLED_VAL = 5;
+
+ /**
+ * Message prefix for locked out accounts
+ */
+ public static final String LOCKEDOUT_PREFIX = PREFIX + LOCKEDOUT_VAL + ": ";
+
+ /**
+ * Message prefix for disabled accounts
+ */
+ public static final String DISABLED_PREFIX = PREFIX + DISABLED_VAL + ": ";
+
+ /**
+ * Message prefix for resych initiation
+ */
+ public static final int RESYNCH_STARTING_VAL = 1;
+
+ /**
+ * Message prefix for resych initiation
+ */
+ public static final String RESYNCH_STARTING_PREFIX = PREFIX + RESYNCH_STARTING_VAL + ": ";
+
+ /**
+ * Message prefix for progressing resych process
+ */
+ public static final int RESYNCH_INPROGRESS_VAL = 2;
+
+ /**
+ * Message prefix for progressing resych process
+ */
+ public static final String RESYNCH_INPROGRESS_PREFIX = PREFIX + RESYNCH_INPROGRESS_VAL + ": ";
+
+ /**
+ * Message prefix for preauth failure
+ */
+ public static final int HOTPAUTH_FAILURE_VAL = 3;
+
+ /**
+ * Message prefix for preauth failure
+ */
+ public static final String HOTPAUTH_FAILURE_PREFIX = PREFIX + HOTPAUTH_FAILURE_VAL + ": ";
+
+ /**
+ * Message for locked out accounts
+ */
+ public static final String LOCKEDOUT_MSG = LOCKEDOUT_PREFIX + "Account locked - contact your administrator!";
+
+ /**
+ * Message for disabled accounts
+ */
+ public static final String DISABLED_MSG = DISABLED_PREFIX + "Account disabled - contact your administrator!";
+
+ /**
+ * Message for resych initiation
+ */
+ public static final String RESYNCH_STARTING_MSG = RESYNCH_STARTING_PREFIX + "Resynch starting - keep entering passwords!";
+
+ /**
+ * Message for progressing resych process
+ */
+ public static final String RESYNCH_INPROGRESS_MSG = RESYNCH_INPROGRESS_PREFIX + "Resynch in progress - keep entering passwords!";
+
+ /**
+ * Message for preauth failure
+ */
+ public static final String HOTPAUTH_FAILURE_MSG = HOTPAUTH_FAILURE_PREFIX + "Preauth failed!";
+
+ /**
+ * Message prefix for inactive accounts
+ */
+ public static final int INACTIVE_VAL = 4;
+
+ /**
+ * Message prefix for inactive accounts
+ */
+ public static final String INACTIVE_PREFIX = PREFIX + INACTIVE_VAL + ": ";
+
+ /**
+ * Message for inactive accounts
+ */
+ public static final String INACTIVE_MSG = INACTIVE_PREFIX + "Account awaiting activation!";
+
+ /**
+ * An unmodifiable list of messages to be indexed by ordinal
+ */
+ private static final String[] MESSAGES;
+
+
+ static
+ {
+ // gotta use vector here for J2ME instead of ArrayList
+
+ Vector messages = new Vector( 6 );
+ messages.addElement( LOCKEDOUT_MSG );
+ messages.addElement( RESYNCH_STARTING_MSG );
+ messages.addElement( RESYNCH_INPROGRESS_MSG );
+ messages.addElement( HOTPAUTH_FAILURE_MSG );
+ messages.addElement( INACTIVE_MSG );
+ messages.addElement( DISABLED_MSG );
+ MESSAGES = new String[messages.size()];
+ messages.copyInto( MESSAGES );
+ }
+
+
+ /**
+ * Gets the error message associated with an ordinal value.
+ *
+ * @param ordinal the error message code
+ * @return the error message
+ */
+ public static String getErrorMessage( int ordinal )
+ {
+ return MESSAGES[ordinal];
+ }
+
+
+ /**
+ * Checks to see if a message has an embedded ordinal value.
+ *
+ * @param message the message containing an embedded ordinal value
+ * @return true if the message has an ordinal value, false otherwise
+ */
+ public static boolean hasEmbeddedOrdinal( String message )
+ {
+ return message.indexOf( PREFIX ) != -1;
+ }
+
+
+ /**
+ * Gets the embedded ordinal value from a message.
+ *
+ * @param message the message containing an embedded ordinal value
+ * @return the ordinal value within the message
+ */
+ public static int getEmbeddedOrdinal( String message )
+ {
+ if ( !hasEmbeddedOrdinal( message ) )
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "Message '" );
+ buf.append( message );
+ buf.append( "' does not contain embedded ordinal" );
+ }
+
+ String pastPrefix = stripPrefix( message, PREFIX );
+
+ return Integer.parseInt( getPrefix( pastPrefix, ':' ) );
+ }
+
+
+ /**
+ * Extracts the ordinal from a string that has it embedded.
+ *
+ * @param s the message with the ordinal embedded
+ * @return the ordinal embedded within the message type
+ */
+ public static int getOrdinal( String s )
+ {
+ String pastPrefix = stripPrefix( s, PREFIX );
+ return Integer.parseInt( getPrefix( pastPrefix, ']' ) );
+ }
+
+
+ private static String getPrefix( String str, char sep )
+ {
+ int index = -1;
+ if ( ( index = str.indexOf( sep ) ) != -1 )
+ {
+ str = str.substring( 0, index );
+ }
+ return str;
+ }
+
+
+ private static String stripPrefix( String str, String prefix )
+ {
+ int index = str.indexOf( prefix );
+ if ( index != -1 )
+ {
+ return str.substring( index + prefix.length() );
+ }
+ return str;
+ }
+}
Added: directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/ResynchParameters.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/ResynchParameters.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/ResynchParameters.java (added)
+++ directory/trunks/triplesec/otp/src/main/java/org/safehaus/otp/ResynchParameters.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,86 @@
+/*
+ * 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.safehaus.otp;
+
+
+/**
+ * HOTP moving factor resynchronization protocol parameters.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public interface ResynchParameters
+{
+ /** an implementation that always returns the default values */
+ ResynchParameters DEFAULTS = new ResynchParameters()
+ {
+ public int getLookaheadSize()
+ {
+ return 10;
+ }
+
+
+ public int getNumResyncValidations()
+ {
+ return 2;
+ }
+
+
+ public int getLockoutCount()
+ {
+ return 3;
+ }
+
+
+ public String toString()
+ {
+ return "(defaults) resync params[lookahead=10, resyncValidations=2, lockoutCount=3]";
+ }
+ };
+
+
+ /**
+ * Gets the HOTP value lookahead window size used to resynchronize the
+ * moving factor for both client and server.
+ *
+ * @return the size of the HOTP lookahead window (s)
+ */
+ int getLookaheadSize();
+
+
+ /**
+ * Gets the number of consecutive HOTP values an out of sync client will
+ * be asked for. 2-3 times is an acceptable and secure value for this
+ * parameter.
+ *
+ * @return the number of consecutive validations for resynch
+ */
+ int getNumResyncValidations();
+
+
+ /**
+ * Gets the 'throttling' (T) parameter used to lock out an account after a
+ * certain number of authentication attempts.
+ *
+ * @return the number of failured authentication attempts before locking
+ * out an account
+ */
+ int getLockoutCount();
+}
Added: directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpAttributesCipherTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpAttributesCipherTest.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpAttributesCipherTest.java (added)
+++ directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpAttributesCipherTest.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,117 @@
+/*
+ * 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.safehaus.otp;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests the HotpAttributesCipher.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class HotpAttributesCipherTest extends TestCase
+{
+ public void testUnsignedByteEncoding()
+ {
+ assertEquals( 0, HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 0 ) ) );
+ assertEquals( 1, HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 1 ) ) );
+ assertEquals( 128, HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 128 ) ) );
+ assertEquals( 129, HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 129 ) ) );
+ assertEquals( 255, HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 255 ) ) );
+
+ try
+ {
+ HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( -2 ) );
+ fail( "should never get here due to IllegalArguemntException on -2" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ }
+
+ try
+ {
+ HotpAttributesCipher.decodeUnsignedByte( HotpAttributesCipher.encodeUnsignedByte( 256 ) );
+ fail( "should never get here due to IllegalArguemntException on 256" );
+ }
+ catch( IllegalArgumentException e )
+ {
+ }
+ }
+
+
+ public void testLongEncoding()
+ {
+ assertEquals( 0, HotpAttributesCipher.decodeLong( HotpAttributesCipher.encodeLong( 0 ), 0 ) );
+ assertEquals( 1, HotpAttributesCipher.decodeLong( HotpAttributesCipher.encodeLong( 1 ), 0 ) );
+
+ assertEquals( 128, HotpAttributesCipher.decodeLong( HotpAttributesCipher.encodeLong( 128 ), 0 ) );
+ assertEquals( -128, HotpAttributesCipher.decodeLong( HotpAttributesCipher.encodeLong( -128 ), 0 ) );
+
+ assertEquals( 2147483647, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( 2147483647 ), 0 ) );
+ assertEquals( -2147483648, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( -2147483648L ), 0 ) );
+
+ assertEquals( 549755813887L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( 549755813887L ), 0 ) );
+ assertEquals( -549755813888L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( -549755813888L ), 0 ) );
+
+ assertEquals( 140737488355327L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( 140737488355327L ), 0 ) );
+ assertEquals( -140737488355328L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( -140737488355328L ), 0 ) );
+
+ assertEquals( -36028797018963968L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( -36028797018963968L ), 0 ) );
+ assertEquals( 36028797018963967L, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( 36028797018963967L ), 0 ) );
+
+ assertEquals( Long.MAX_VALUE, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( Long.MAX_VALUE ), 0 ) );
+ assertEquals( Long.MIN_VALUE, HotpAttributesCipher.decodeLong(
+ HotpAttributesCipher.encodeLong( Long.MIN_VALUE ), 0 ) );
+ }
+
+
+ public void testEncryptDecrypt() throws Exception
+ {
+ HotpAttributes attributes = new HotpAttributes( 12341234,
+ new byte[] { 0x45, 0x23, 0x12, 0x34, 0x45, 0x23, 0x23, 0x61 } );
+ String encrypted = HotpAttributesCipher.encrypt( "secret", attributes );
+ HotpAttributes decrypted = HotpAttributesCipher.decrypt( "secret", encrypted );
+ assertEquals( attributes, decrypted );
+
+ attributes = new HotpAttributes( 3282543502398475L,
+ new byte[] { 0x45, 0x23, 0x12, 0x34, 0x45, 0x23, 0x12, 0x34, 0x45, 0x23, 0x23, 0x61 } );
+ encrypted = HotpAttributesCipher.encrypt( "longer than expected secret", attributes );
+ decrypted = HotpAttributesCipher.decrypt( "longer than expected secret", encrypted );
+ assertEquals( attributes, decrypted );
+
+ attributes = new HotpAttributes( 3282543502398475L,
+ new byte[] { 0x45, 0x23, 0x12, 0x34, 0x45, 0x23, 0x12, 0x34, 0x45, 0x23, 0x23, 0x61 } );
+ encrypted = HotpAttributesCipher.encrypt( "longer than expected secret", attributes );
+ decrypted = HotpAttributesCipher.decrypt( "secret", encrypted );
+ assertNull( decrypted );
+ }
+}
Added: directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpErrorConstantsTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpErrorConstantsTest.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpErrorConstantsTest.java (added)
+++ directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpErrorConstantsTest.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,98 @@
+/*
+ * 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.safehaus.otp;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests a couple of the methods in {@link HotpErrorConstants}.
+ *
+ * @see HotpErrorConstants
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class HotpErrorConstantsTest extends TestCase
+{
+ /**
+ * Tests the {@link HotpErrorConstants#hasEmbeddedOrdinal(String)} method.
+ */
+ public void testHasEmbeddedOrdinal()
+ {
+ assertTrue( HotpErrorConstants.hasEmbeddedOrdinal( HotpErrorConstants.HOTPAUTH_FAILURE_MSG ) );
+
+ assertTrue( HotpErrorConstants.hasEmbeddedOrdinal( HotpErrorConstants.LOCKEDOUT_MSG ) );
+
+ assertTrue( HotpErrorConstants.hasEmbeddedOrdinal( HotpErrorConstants.RESYNCH_INPROGRESS_MSG ) );
+
+ assertTrue( HotpErrorConstants.hasEmbeddedOrdinal( HotpErrorConstants.RESYNCH_STARTING_MSG ) );
+ }
+
+
+ /**
+ * Tests the {@link HotpErrorConstants#getEmbeddedOrdinal(String)} method.
+ */
+ public void testGetEmbeddedOrdinal()
+ {
+ int ordinal = HotpErrorConstants.getEmbeddedOrdinal( HotpErrorConstants.HOTPAUTH_FAILURE_MSG );
+
+ assertEquals( HotpErrorConstants.HOTPAUTH_FAILURE_VAL, ordinal );
+
+ ordinal = HotpErrorConstants.getEmbeddedOrdinal( HotpErrorConstants.LOCKEDOUT_MSG );
+
+ assertEquals( HotpErrorConstants.LOCKEDOUT_VAL, ordinal );
+
+ ordinal = HotpErrorConstants.getEmbeddedOrdinal( HotpErrorConstants.RESYNCH_INPROGRESS_MSG );
+
+ assertEquals( HotpErrorConstants.RESYNCH_INPROGRESS_VAL, ordinal );
+
+ ordinal = HotpErrorConstants.getEmbeddedOrdinal( HotpErrorConstants.RESYNCH_STARTING_MSG );
+
+ assertEquals( HotpErrorConstants.RESYNCH_STARTING_VAL, ordinal );
+
+ String msg = "Generic error (description in e-text) (60) - HOTP-1";
+ ordinal = HotpErrorConstants.getEmbeddedOrdinal( msg );
+ assertEquals( HotpErrorConstants.RESYNCH_STARTING_VAL, ordinal );
+ }
+
+
+ /**
+ * Tests the {@link HotpErrorConstants#getErrorMessage(int)} method.
+ */
+ public void testGetErrorMessage()
+ {
+ String message = HotpErrorConstants.getErrorMessage( HotpErrorConstants.HOTPAUTH_FAILURE_VAL );
+
+ assertEquals( HotpErrorConstants.HOTPAUTH_FAILURE_MSG, message );
+
+ message = HotpErrorConstants.getErrorMessage( HotpErrorConstants.LOCKEDOUT_VAL );
+
+ assertEquals( HotpErrorConstants.LOCKEDOUT_MSG, message );
+
+ message = HotpErrorConstants.getErrorMessage( HotpErrorConstants.RESYNCH_INPROGRESS_VAL );
+
+ assertEquals( HotpErrorConstants.RESYNCH_INPROGRESS_MSG, message );
+
+ message = HotpErrorConstants.getErrorMessage( HotpErrorConstants.RESYNCH_STARTING_VAL );
+
+ assertEquals( HotpErrorConstants.RESYNCH_STARTING_MSG, message );
+ }
+}
Added: directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpTest.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpTest.java (added)
+++ directory/trunks/triplesec/otp/src/test/org/safehaus/otp/HotpTest.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.safehaus.otp;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests the Hotp class' methods and the HOTP algorithm implementation.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @version $Rev: 585 $
+ */
+public class HotpTest extends TestCase
+{
+ public static final byte[] SECRET = { '1', '2', '3', '4', '5', '6', '7', '8', '7', '9',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
+
+ public void testGenerateDraftData() throws Exception
+ {
+ for( int ii = 0; ii < 10; ii++ )
+ {
+ assertEquals( OneTimePasswordAlgorithm.generateOTP( SECRET, ii, 6, 0 ), Hotp.generate( SECRET, ii, 6 ) );
+ }
+ }
+
+ public void testDump() throws Exception
+ {
+ for( int ii = 0; ii < 10; ii++ )
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( ii );
+ buf.append( " = " );
+ buf.append( Hotp.generate( SECRET, ii, 6 ) );
+ System.out.println( buf.toString() );
+ }
+ }
+}
Added: directory/trunks/triplesec/otp/src/test/org/safehaus/otp/OneTimePasswordAlgorithm.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/otp/src/test/org/safehaus/otp/OneTimePasswordAlgorithm.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/otp/src/test/org/safehaus/otp/OneTimePasswordAlgorithm.java (added)
+++ directory/trunks/triplesec/otp/src/test/org/safehaus/otp/OneTimePasswordAlgorithm.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,86 @@
+/*
+ * 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.safehaus.otp;
+
+
+/**
+ * This class contains static methods that are used to calculate the
+ * One-Time Password (OTP) using JCE to provide the HMAC-SHA1.
+ *
+ * @author Loren Hart
+ * @version 1.0
+ */
+public class OneTimePasswordAlgorithm
+{
+ private static final int[] DIGITS_POWER
+ // 0 1 2 3 4 5 6 7 8
+ = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
+
+
+ /**
+ * This method generates an OTP value for the given
+ * set of parameters.
+ *
+ * @param secret the shared secret
+ * @param movingFactor the counter, time, or other value that
+ * changes on a per use basis.
+ * @param digits the number of digits in the OTP
+ * @param truncationOffset the offset into the MAC result to
+ * begin truncation. If this value is out of
+ * the range of 0 ... 15, then dynamic
+ * truncation will be used.
+ * Dynamic truncation is when the last 4
+ * bits of the last byte of the MAC are
+ * used to determine the start offset.
+ * @return A numeric String in base 10 that includes
+ * codeDigits digits plus the optional checksum
+ * digit if requested.
+ */
+ static public String generateOTP( byte[] secret, long movingFactor, int digits, int truncationOffset )
+ {
+ // put movingFactor value into text byte array
+ StringBuffer result = new StringBuffer();
+
+ // compute hmac hash
+ byte[] hash = Hotp.stepOne( secret, movingFactor );
+
+ // put selected bytes into result int
+ int offset = hash[hash.length - 1] & 0xf;
+ if ( ( 0 <= truncationOffset ) && ( truncationOffset < ( hash.length - 4 ) ) )
+ {
+ offset = truncationOffset;
+ }
+
+ int binary = ( ( hash[offset] & 0x7f ) << 24 ) |
+ ( ( hash[offset + 1] & 0xff ) << 16 ) |
+ ( ( hash[offset + 2] & 0xff ) << 8 ) |
+ ( hash[offset + 3] & 0xff );
+
+
+ int otp = binary % DIGITS_POWER[digits];
+ String initial = Integer.toString( otp );
+ result.append( initial );
+ while ( result.length() < digits )
+ {
+ result.insert( 0, "0" );
+ }
+ return result.toString();
+ }
+}
Added: directory/trunks/triplesec/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/pom.xml?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/pom.xml (added)
+++ directory/trunks/triplesec/pom.xml Tue Dec 12 07:23:31 2006
@@ -0,0 +1,356 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.safehaus.triplesec</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>build</artifactId>
+ <name>Triplesec</name>
+ <packaging>pom</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <url>http://triplesec.apache.org/maven2/</url>
+
+ <repositories>
+ <!-- For apacheds snapshots
+ <repository>
+ <id>apachecvs</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://cvs.apache.org/maven-snapshot-repository</url>
+ </repository>
+ -->
+
+ <repository>
+ <id>safehaus</id>
+ <name>Repository for Safehaus Artifacts</name>
+ <url>http://m2.safehaus.org</url>
+ </repository>
+
+ <repository>
+ <id>java.net</id>
+ <url>https://maven-repository.dev.java.net/nonav/repository</url>
+ <layout>legacy</layout>
+ </repository>
+ </repositories>
+
+ <distributionManagement>
+ <repository>
+ <id>safehaus</id>
+ <url>
+ scp://safehaus.org/home/domains/m2_safehaus_org/public_html
+ </url>
+ </repository>
+ <snapshotRepository>
+ <id>safehaus</id>
+ <url>
+ scp://safehaus.org/home/domains/m2_safehaus_org/public_html
+ </url>
+ </snapshotRepository>
+ <site>
+ <id>triplesec.website</id>
+ <url>scp://safehaus.org/home/projects/triplesec/public_html/maven</url>
+ </site>
+ </distributionManagement>
+
+ <issueManagement>
+ <system>JIRA</system>
+ <url>http://jira.safehaus.org/browse/TRIPLESEC</url>
+ </issueManagement>
+
+ <inceptionYear>2005</inceptionYear>
+
+ <mailingLists>
+ <mailingList>
+ <name>Safehaus Developers List</name>
+ <subscribe>dev-subscribe@safehaus.org</subscribe>
+ <unsubscribe>dev-unsubscribe@safehaus.org</unsubscribe>
+ <post>dev@safehaus.org</post>
+ <archive>http://www.safehaus.org/pipermail/dev</archive>
+ </mailingList>
+ <mailingList>
+ <name>Safehaus Commits (SVN) List</name>
+ <subscribe>svn-notify-subscribe@safehaus.org</subscribe>
+ <unsubscribe>svn-notify-unsubscribe@safehaus.org</unsubscribe>
+ </mailingList>
+ </mailingLists>
+
+ <!-- ordered alphabetically by id -->
+ <developers>
+ <developer>
+ <id>akarasulu</id>
+ </developer>
+ <developer>
+ <id>ersiner</id>
+ </developer>
+ <developer>
+ <id>elecharny</id>
+ </developer>
+ <developer>
+ <id>trustin</id>
+ </developer>
+ <developer>
+ <id>tbennett</id>
+ </developer>
+ </developers>
+
+ <licenses>
+ <license>
+ <name>Open Software License, Version 2.1</name>
+ <url>http://www.opensource.org/licenses/osl-2.1.txt</url>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:svn:https://svn.safehaus.org/repos/triplesec/trunk</connection>
+ <url>https://svn.safehaus.org/repos/triplesec/trunk</url>
+ <developerConnection>scm:svn:https://svn.safehaus.org/repos/triplesec/trunk</developerConnection>
+ </scm>
+
+ <organization>
+ <name>Safehaus</name>
+ <url>http://safehaus.org</url>
+ </organization>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </plugin>
+
+
+ <plugin>
+ <inherited>false</inherited>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>site</phase>
+ <configuration>
+ <tasks>
+ <javadoc destdir="target/site/apidocs" author="true" use="true" windowtitle="Safehaus Triplesec">
+ <sourcepath>
+ <dirset dir=".">
+ <include name="*/src/main/java"/>
+ <exclude name="directory"/>
+ </dirset>
+ </sourcepath>
+ <package name="org.safehaus.triplesec.*"/>
+ </javadoc>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <reporting>
+ <excludeDefaults>true</excludeDefaults>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>project-team</report>
+ <report>mailing-list</report>
+ <report>issue-tracking</report>
+ <report>license</report>
+ <report>scm</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+
+ <modules>
+ <module>changelog</module>
+ <module>configuration</module>
+ <module>configuration-io</module>
+ <module>crypto</module>
+ <module>otp</module>
+ <module>profile</module>
+ <module>testdata</module>
+ <module>jaas</module>
+ <module>sms</module>
+ <module>store</module>
+ <module>verifier</module>
+ <module>main</module>
+ <module>integration</module>
+ <module>tools</module>
+ <module>admin-api</module>
+ <module>guardian-api</module>
+ <module>guardian-ldap</module>
+ <module>guardian-ldif</module>
+ <module>utils-hauskeys</module>
+ <module>wicket-tools</module>
+ <module>webapp-root</module>
+ <module>webapp-registration</module>
+ <module>webapp-activation</module>
+ <module>webapp-demo</module>
+ <module>webapp-servlet-demo</module>
+ <module>webapp-wicket-admin</module>
+ <module>webapp-config</module>
+ <module>webapp-changelog</module>
+ <module>swing-admin</module>
+ <module>swing-demo</module>
+ </modules>
+
+ </profile>
+ <profile>
+ <id>installers</id>
+ <activation>
+ <property><name>installers</name></property>
+ </activation>
+
+ <modules>
+ <module>changelog</module>
+ <module>configuration</module>
+ <module>configuration-io</module>
+ <module>crypto</module>
+ <module>otp</module>
+ <module>profile</module>
+ <module>testdata</module>
+ <module>jaas</module>
+ <module>sms</module>
+ <module>store</module>
+ <module>verifier</module>
+ <module>main</module>
+ <module>integration</module>
+ <module>tools</module>
+ <module>admin-api</module>
+ <module>guardian-api</module>
+ <module>guardian-ldap</module>
+ <module>guardian-ldif</module>
+ <module>utils-hauskeys</module>
+ <module>wicket-tools</module>
+ <module>webapp-root</module>
+ <module>webapp-registration</module>
+ <module>webapp-activation</module>
+ <module>webapp-demo</module>
+ <module>webapp-servlet-demo</module>
+ <module>webapp-wicket-admin</module>
+ <module>webapp-config</module>
+ <module>webapp-changelog</module>
+ <module>smstrial-schema</module>
+ <module>webapp-smstrial</module>
+ <module>swing-admin</module>
+ <module>swing-demo</module>
+
+ <module>installers</module>
+ </modules>
+
+ </profile>
+ <profile>
+ <id>smstrial</id>
+ <activation>
+ <property><name>smstrial</name></property>
+ </activation>
+
+ <modules>
+ <module>smstrial-schema</module>
+ <module>webapp-smstrial</module>
+ </modules>
+
+ </profile>
+ <profile>
+ <id>all</id>
+ <activation>
+ <property><name>all</name></property>
+ </activation>
+
+ <modules>
+ <module>changelog</module>
+ <module>configuration</module>
+ <module>configuration-io</module>
+ <module>crypto</module>
+ <module>otp</module>
+ <module>profile</module>
+ <module>testdata</module>
+ <module>jaas</module>
+ <module>sms</module>
+ <module>store</module>
+ <module>verifier</module>
+ <module>main</module>
+ <module>integration</module>
+ <module>tools</module>
+ <module>admin-api</module>
+ <module>guardian-api</module>
+ <module>guardian-ldap</module>
+ <module>guardian-ldif</module>
+ <module>utils-hauskeys</module>
+ <module>wicket-tools</module>
+ <module>webapp-root</module>
+ <module>webapp-registration</module>
+ <module>webapp-activation</module>
+ <module>webapp-demo</module>
+ <module>webapp-servlet-demo</module>
+ <module>webapp-wicket-admin</module>
+ <module>webapp-config</module>
+ <module>webapp-changelog</module>
+ <module>swing-admin</module>
+ <module>swing-demo</module>
+
+ <module>smstrial-schema</module>
+ <module>webapp-smstrial</module>
+
+ <module>installers</module>
+ </modules>
+
+ </profile>
+ </profiles>
+
+</project>
Added: directory/trunks/triplesec/profile/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/pom.xml?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/pom.xml (added)
+++ directory/trunks/triplesec/profile/pom.xml Tue Dec 12 07:23:31 2006
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.safehaus.triplesec</groupId>
+ <artifactId>build</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>triplesec-profile</artifactId>
+ <name>Triplesec Profile API</name>
+ <packaging>jar</packaging>
+ <description>
+ Triplesec Profile API
+ </description>
+</project>
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfile.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfile.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfile.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,155 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * A base Profile bean.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class BaseProfile implements Profile
+{
+ /** the lable or identifier for this profile */
+ protected String label;
+
+ /** the shared secret */
+ protected byte[] secret;
+
+ /** the moving factor or counter */
+ protected long factor;
+
+ /** additional (optional) account info */
+ protected String info = "";
+
+ /** whether or not this profile is disabled */
+ protected boolean disabled = false;
+
+ /**
+ * Creates a Profile bean with all properties set to defaults.
+ */
+ protected BaseProfile()
+ {
+ // do nothing
+ }
+
+
+ /**
+ * Creates a new profile using a unique label, shared secret key, and moving
+ * factor for the OTP based account.
+ *
+ * @param label a unique label for this BaseProfile
+ * @param factor the moving factor (counter)
+ * @param secret the 160 bit shared secret key
+ */
+ public BaseProfile( String label, long factor, byte[] secret )
+ {
+ this.label = label;
+ this.secret = secret;
+ this.factor = factor;
+ }
+
+
+ /**
+ * Creates a new profile using a unique label, shared secret key, and moving
+ * factor for the OTP based account.
+ *
+ * @param label a unique label for this BaseProfile
+ * @param factor the moving factor (counter)
+ * @param secret the shared secret key
+ */
+ public BaseProfile( String label, long factor, byte[] secret, String info )
+ {
+ this.label = label;
+
+ this.secret = secret;
+
+ this.factor = factor;
+
+ this.info = info;
+ }
+
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+
+ void setLabel( String label )
+ {
+ this.label = label;
+ }
+
+
+ public byte[] getSecret()
+ {
+ return secret;
+ }
+
+
+ void setSecret( byte[] secret )
+ {
+ this.secret = secret;
+ }
+
+
+ public long getFactor()
+ {
+ return factor;
+ }
+
+
+ void setFactor( long factor )
+ {
+ this.factor = factor;
+ }
+
+
+ void incrementFactor()
+ {
+ this.factor++;
+ }
+
+
+ public String getInfo()
+ {
+ return info;
+ }
+
+
+ void setInfo( String info )
+ {
+ this.info = info;
+ }
+
+
+ public boolean isDisabled()
+ {
+ return disabled;
+ }
+
+
+ void setDisabled( boolean disabled )
+ {
+ this.disabled = disabled;
+ }
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfileModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfileModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfileModifier.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseProfileModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,208 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * A BaseProfile modifier.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class BaseProfileModifier
+{
+ /** the moveing factor delta */
+ protected long factor;
+
+ /** the optional account info delta */
+ protected String info;
+
+ /** the delta for the account label */
+ protected String label;
+
+ /** the delta for the shared secret */
+ protected byte[] secret;
+
+ private boolean disabled;
+
+
+ // ------------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Creates a BaseProfileModifier without any initial values set.
+ */
+ public BaseProfileModifier()
+ {
+ }
+
+
+ /**
+ * Creates a BaseProfileModifier using initially the values of an existing profile.
+ *
+ * @param profile the profile to use for initial values
+ */
+ public BaseProfileModifier( Profile profile )
+ {
+ factor = profile.getFactor();
+ info = profile.getInfo();
+ label = profile.getLabel();
+ secret = profile.getSecret();
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Builder method
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Builds the profile using all the properties.
+ *
+ * @return the changed properties
+ */
+ public BaseProfile getProfile()
+ {
+ BaseProfile profile = new BaseProfile( getLabel(), getFactor(), getSecret(), getInfo() );
+ profile.setDisabled( this.disabled );
+ return profile;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Modifier methods
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Set's whether or not this profile is disabled.
+ */
+ public void setDisabled( boolean disabled )
+ {
+ this.disabled = disabled;
+ }
+
+
+ /**
+ * Sets the label used to identify the Profile
+ *
+ * @param label the new label for the Profile
+ */
+ public void setLabel( String label )
+ {
+ this.label = label;
+ }
+
+
+ /**
+ * Sets the shared secret key used to generate the HOTP value.
+ *
+ * @param secret the shared secret key between client and server
+ */
+ public void setSecret( byte[] secret )
+ {
+ this.secret = secret;
+ }
+
+
+ /**
+ * Sets the moving factor used to generate an OTP.
+ *
+ * @param factor the OTP moving factor (counter)
+ */
+ public void setFactor( long factor )
+ {
+ this.factor = factor;
+ }
+
+
+ /**
+ * Increments the OTP moving factor (counter). This is called after the
+ * password is generated. Then this Profile is serialized back to the
+ * profile store.
+ */
+ public void incrementFactor()
+ {
+ factor = getFactor() + 1;
+ }
+
+
+ /**
+ * Sets additional account information about this Profile. Null values will
+ * become empty Strings when serializing and resusitating Profile records.
+ *
+ * @param info additional account information about this Profile
+ */
+ public void setInfo( String info )
+ {
+ this.info = info;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // protected accessor methods
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Gets the altered label associated with this ProfileModifier.
+ *
+ * @return the altered label that identifies this ProfileModifier
+ */
+ protected String getLabel()
+ {
+ return label;
+ }
+
+
+ /**
+ * Gets the altered shared secret key used to generate the HOTP value.
+ *
+ * @return the altered shared secret key between client and server
+ */
+ protected byte[] getSecret()
+ {
+ return secret;
+ }
+
+
+ /**
+ * The altered moving factor (counter) used to generate an OTP.
+ *
+ * @return altered the OTP moving factor (counter)
+ */
+ protected long getFactor()
+ {
+ return factor;
+ }
+
+
+ /**
+ * Gets altered additional account information about this ProfileModifier.
+ *
+ * @return altered additional account information
+ */
+ protected String getInfo()
+ {
+ return info;
+ }
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfile.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfile.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfile.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,205 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * The base profile implementation used by servers.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class BaseServerProfile extends BaseProfile implements ServerProfile
+{
+ /** the user id associated with this profile */
+ private String id;
+ /** the realm associated with this profile */
+ private String realm;
+ /** the successful resynch attempt count */
+ private int resynchCount = -1;
+ /** the number of auth failures within a server epoch */
+ private int failuresInEpoch;
+ /** the activation key for this profile if it has not yet been activated */
+ private String activationKey;
+ private String tokenPin;
+ private String notifyBy = "sms";
+ private byte[] password;
+
+
+ /**
+ * Creates a new profile using a unique label, shared secret key, and moving
+ * factor for the OTP based account.
+ *
+ * @param id the user id associated with this profile
+ * @param realm the authentication realm this profile is in
+ * @param label a unique label for this BaseProfile
+ * @param factor the moving factor (counter)
+ * @param secret the 160 bit shared secret key
+ */
+ public BaseServerProfile( String id, String realm, String label, long factor, byte[] secret,
+ String pin, byte[] password )
+ {
+ this.id = id;
+ this.realm = realm;
+ this.label = label;
+ this.secret = secret;
+ this.factor = factor;
+ this.tokenPin = pin;
+ this.password = password;
+ }
+
+
+ /**
+ * Creates a new profile using a unique label, shared secret key, and moving
+ * factor for the OTP based account.
+ *
+ * @param id the user id associated with this profile
+ * @param realm the authentication realm this profile is in
+ * @param label a unique label for this BaseProfile
+ * @param factor the moving factor (counter)
+ * @param secret the shared secret key
+ */
+ public BaseServerProfile( String id, String realm, String label, long factor, byte[] secret,
+ String pin, byte[] password, String info, String activationKey )
+ {
+ this.id = id;
+ this.realm = realm;
+ this.label = label;
+ this.secret = secret;
+ this.factor = factor;
+ this.tokenPin = pin;
+ this.password = password;
+ this.info = info;
+ this.activationKey = activationKey;
+ }
+
+
+ public String getUserId()
+ {
+ return id;
+ }
+
+
+ public String getRealm()
+ {
+ return realm;
+ }
+
+
+ public int getResynchCount()
+ {
+ return this.resynchCount;
+ }
+
+
+ public int getFailuresInEpoch()
+ {
+ return this.failuresInEpoch;
+ }
+
+
+ public boolean isActive()
+ {
+ return activationKey == null || activationKey.length() == 0;
+ }
+
+
+ public String getActivationKey()
+ {
+ return activationKey;
+ }
+
+
+ public String getTokenPin()
+ {
+ return tokenPin;
+ }
+
+
+ void setTokenPin( String tokenPin )
+ {
+ this.tokenPin = tokenPin;
+ }
+
+
+ public byte[] getPassword()
+ {
+ return password;
+ }
+
+
+ void setPassword( byte[] password )
+ {
+ this.password = password;
+ }
+
+ void setUserId( String id )
+ {
+ this.id = id;
+ }
+
+
+ void setRealm( String domain )
+ {
+ this.realm = domain;
+ }
+
+
+ void setResynchCount( int resynchCount )
+ {
+ this.resynchCount = resynchCount;
+ }
+
+
+ void setFailuresInEpoch( int failuresInEpoch )
+ {
+ this.failuresInEpoch = failuresInEpoch;
+ }
+
+
+ void setActivationKey( String activationKey )
+ {
+ this.activationKey = activationKey;
+ }
+
+
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "ServerProfile[realm=" ).append( this.realm );
+ buf.append( ", id = ").append( this.id );
+ buf.append( ", factor = *****" ); // do not log this for security reasons
+ buf.append( ", secret = *****" ); // do not log this for security reasons
+ buf.append( ", pin = *****" ); // do not log this for security reasons
+ buf.append( ", password = *****" ); // do not log this for security reasons
+ buf.append( ", failuresInEpoch = " ).append( this.failuresInEpoch );
+ buf.append( ", info = " ).append( this.info );
+ buf.append( ", label = " ).append( this.label );
+ buf.append( ", resynchCount = " ).append( this.resynchCount );
+ buf.append( "]" );
+ return buf.toString();
+ }
+
+
+ public String getNotifyBy()
+ {
+ return notifyBy;
+ }
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfileModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfileModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfileModifier.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/BaseServerProfileModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,243 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * A BaseServerProfileModifier.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class BaseServerProfileModifier extends BaseProfileModifier
+{
+ /** the delta for the user id */
+ private String id;
+
+ /** the delta for the realm */
+ private String realm;
+
+ /** the delta for the resynchronization counts that have succeed */
+ private int resynchCount;
+
+ /** the delta for the number of failures to authenticate in epoch */
+ private int failuresInEpoch;
+
+ private String activationKey;
+
+ private byte[] password;
+ private String tokenPin;
+
+
+ // ------------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Creates a BaseServerProfileModifier without any initial values.
+ */
+ public BaseServerProfileModifier()
+ {
+ super();
+ }
+
+
+ /**
+ * Creates a BaseServerProfileModifier with initial values copied from an existing profile.
+ *
+ * @param profile the existing profile used for initial values
+ */
+ public BaseServerProfileModifier( ServerProfile profile )
+ {
+ super( profile );
+
+ this.resynchCount = profile.getResynchCount();
+ this.id = profile.getUserId();
+ this.factor = profile.getFactor();
+ this.realm = profile.getRealm();
+ this.failuresInEpoch = profile.getFailuresInEpoch();
+ this.info = profile.getInfo();
+ this.activationKey = profile.getActivationKey();
+ this.password = profile.getPassword();
+ this.tokenPin = profile.getTokenPin();
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Builder method
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Builds the profile using all its altered properties.
+ *
+ * @return the changed properties
+ */
+ public BaseServerProfile getServerProfile()
+ {
+ BaseServerProfile profile = new BaseServerProfile( this.id, this.realm, getLabel(),
+ getFactor(), getSecret(), getTokenPin(), getPassword() );
+ profile.setInfo( info );
+ profile.setFailuresInEpoch( failuresInEpoch );
+ profile.setResynchCount( resynchCount );
+ profile.setActivationKey( activationKey );
+ return profile;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Modifier methods
+ // ------------------------------------------------------------------------
+
+
+ public void setPassword( byte[] password )
+ {
+ this.password = password;
+ }
+
+
+ public void setTokenPin( String tokenPin )
+ {
+ this.tokenPin = tokenPin;
+ }
+
+
+ /**
+ * Sets the number of successful consecutive resync operations that have
+ * passed.
+ *
+ * @param resynchCount the number of successful resynch passes until now
+ */
+ public void setResynchCount( int resynchCount )
+ {
+ this.resynchCount = resynchCount;
+ }
+
+
+ /**
+ * Gets the unique user id associated with this profile.
+ *
+ * @param id the unique user id associated with this profile
+ */
+ public void setUserId( String id )
+ {
+ this.id = id;
+ }
+
+
+ /**
+ * Gets the authentication realm associated with this Profile.
+ *
+ * @param realm the authentication realm associated with this Profile
+ */
+ public void setRealm( String realm )
+ {
+ this.realm = realm;
+ }
+
+
+ /**
+ * Sets the number of authentication failures within an epoch.
+ *
+ * @param failuresInEpoch the number of authentication failures within an epoch
+ */
+ public void setFailuresInEpoch( int failuresInEpoch )
+ {
+ this.failuresInEpoch = failuresInEpoch;
+ }
+
+
+ public void setActivationKey ( String activationKey )
+ {
+ this.activationKey = activationKey;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Protected accessorr methods
+ // ------------------------------------------------------------------------
+
+
+ protected String getTokenPin()
+ {
+ return tokenPin;
+ }
+
+
+ protected byte[] getPassword()
+ {
+ return password;
+ }
+
+
+ /**
+ * Gets the unique user id associated with this profile.
+ *
+ * @return the unique user id associated with this profile
+ */
+ protected String getUserId()
+ {
+ return this.id;
+ }
+
+
+ /**
+ * Gets the authentication realm associated with this Profile.
+ *
+ * @return the authentication realm associated with this Profile
+ */
+ protected String getRealm()
+ {
+ return this.realm;
+ }
+
+
+ /**
+ * Gets the number of successful consecutive resync operations that have
+ * passed. This count is set to a negative number to denote that no resynch
+ * is in progress. When users are undergoing the resynch process they may
+ * be asked to type in their password a certain number of times
+ * consecutively. Each time the user succeeds this counter is incremented.
+ * When the user has successfully completed the resynch operation the
+ * counter is set to a negative value. If the user fails during resynch
+ * the counter is set to 0.
+ *
+ * @return the number of successful resynch passes until now
+ */
+ protected int getResynchCount()
+ {
+ return this.resynchCount;
+ }
+
+
+ /**
+ * Gets the number of authentication failures within an epoch. The number
+ * of authentication failures are tracked here within time periods
+ * determined by the server. If the user exceeds some threshold the account
+ * is automatically locked to prevent brute force attacks.
+ *
+ * @return the number of authentication failures within an epoch
+ */
+ protected int getFailuresInEpoch()
+ {
+ return this.failuresInEpoch;
+ }
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/Profile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/Profile.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/Profile.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/Profile.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * The interface for a Safehaus account profile.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public interface Profile
+{
+ /**
+ * Check to see if this profile is disabled.
+ *
+ * @return true if the profile is disabled, false if it is not
+ */
+ boolean isDisabled();
+
+ /**
+ * Gets the label associated with this Profile.
+ *
+ * @return the label that identifies this Profile
+ */
+ String getLabel();
+
+
+ /**
+ * Gets the shared secret key used to generate the HOTP value.
+ *
+ * @return the shared secret key between client and server
+ */
+ byte[] getSecret();
+
+
+ /**
+ * The moving factor (counter) used to generate an OTP.
+ *
+ * @return the OTP moving factor (counter)
+ */
+ long getFactor();
+
+
+ /**
+ * Gets additional account information about this Profile.
+ *
+ * @return additional account information
+ */
+ String getInfo();
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ProfileUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ProfileUtils.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ProfileUtils.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ProfileUtils.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,198 @@
+/*
+ * 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.safehaus.profile;
+
+
+import java.io.*;
+
+
+/**
+ * Utility functions dealing with account Profiles.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class ProfileUtils
+{
+
+
+ /**
+ * Generates the serialized representation of a Profile.
+ *
+ * @param profile the Profile to serialize using the record format
+ * @return the serialized Profile
+ */
+ public static byte[] serialize( Profile profile ) throws IOException
+ {
+ ByteArrayOutputStream arrayOut = null;
+
+ DataOutputStream dataOut = null;
+
+ try
+ {
+ arrayOut = new ByteArrayOutputStream();
+
+ dataOut = new DataOutputStream( arrayOut );
+
+ /*
+ * We write the members in the following order:
+ *
+ * 1). the label value
+ * 2). moving factor
+ * 3). additional account information if any at all
+ * 4). the shared secret
+ */
+
+ dataOut.writeUTF( profile.getLabel() );
+
+ dataOut.writeLong( profile.getFactor() );
+
+ if ( profile.getInfo() == null )
+ {
+ dataOut.writeUTF( "" );
+ }
+ else
+ {
+ dataOut.writeUTF( profile.getInfo() );
+ }
+
+ dataOut.write( profile.getSecret() );
+
+ dataOut.flush();
+ }
+ finally
+ {
+ if ( dataOut != null )
+ {
+ dataOut.close();
+ }
+
+ if ( arrayOut != null )
+ {
+ arrayOut.close();
+ }
+ }
+
+ return arrayOut.toByteArray();
+ }
+
+
+ /**
+ * Creates a Profile by resusitating a serialized profile from a record
+ * format.
+ *
+ * @param rec the serialized Profile record
+ * @throws IOException if there are problems resusitating the fields
+ */
+ public static final Profile create( byte[] rec ) throws IOException
+ {
+ BaseProfileModifier modifier = new BaseProfileModifier();
+
+ ByteArrayInputStream arrayIn = null;
+
+ DataInputStream dataIn = null;
+
+ try
+ {
+ arrayIn = new ByteArrayInputStream( rec );
+
+ dataIn = new DataInputStream( arrayIn );
+
+ /*
+ * We read the members in the following order which is in the same
+ * order we write them:
+ *
+ * 1). the label value
+ * 2). moving factor
+ * 3). additional account information if any at all
+ * 4). the shared secret
+ */
+
+ modifier.setLabel( dataIn.readUTF() );
+
+ modifier.setFactor( dataIn.readLong() );
+
+ modifier.setInfo( dataIn.readUTF() );
+
+ byte[] buf = new byte[100];
+ int ammount = dataIn.read( buf );
+ byte[] resized = new byte[ammount];
+ System.arraycopy( buf, 0, resized, 0, ammount );
+ modifier.setSecret( resized );
+ }
+ finally
+ {
+ if ( arrayIn != null )
+ {
+ arrayIn.close();
+ }
+
+ if ( dataIn != null )
+ {
+ dataIn.close();
+ }
+ }
+
+ return modifier.getProfile();
+ }
+
+
+ /**
+ * Gets the label of a Profile from the raw record without creating a
+ * Profile object. This is a very efficient method to use while filtering
+ * trying to match for specific Profiles by label.
+ *
+ * @param rec the raw serialized Profile
+ * @return the Profile record's label field
+ * @throws java.io.IOException if there is a problem accessing the serialized data
+ */
+ public static final String getLabel( byte[] rec ) throws IOException
+ {
+ ByteArrayInputStream arrayIn = null;
+
+ DataInputStream dataIn = null;
+
+ String label = null;
+
+
+ try
+ {
+ arrayIn = new ByteArrayInputStream( rec );
+
+ dataIn = new DataInputStream( arrayIn );
+
+ label = dataIn.readUTF();
+ }
+ finally
+ {
+ if ( dataIn != null )
+ {
+ dataIn.close();
+ }
+
+ if ( arrayIn != null )
+ {
+ arrayIn.close();
+ }
+ }
+
+ return label;
+ }
+}
Added: directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ServerProfile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ServerProfile.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ServerProfile.java (added)
+++ directory/trunks/triplesec/profile/src/main/java/org/safehaus/profile/ServerProfile.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,94 @@
+/*
+ * 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.safehaus.profile;
+
+
+/**
+ * A HOTP validation server needs more parameters for a Profile which are
+ * modelled within this interface which extends the Profile interface.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public interface ServerProfile extends Profile
+{
+ /**
+ * Gets the unique user id associated with this profile.
+ *
+ * @return the unique user id associated with this profile
+ */
+ String getUserId();
+
+
+ /**
+ * Gets the authentication realm associated with this Profile.
+ *
+ * @return the authentication realm associated with this Profile
+ */
+ String getRealm();
+
+
+ /**
+ * Gets the number of successful consecutive resync operations that have
+ * passed. This count is set to a negative number to denote that no resynch
+ * is in progress. When users are undergoing the resynch process they may
+ * be asked to type in their password a certain number of times
+ * consecutively. Each time the user succeeds this counter is incremented.
+ * When the user has successfully completed the resynch operation the
+ * counter is set to a negative value. If the user fails during resynch
+ * the counter is set to 0.
+ *
+ * @return the number of successful resynch passes until now
+ */
+ int getResynchCount();
+
+ /**
+ * Gets the number of authentication failures within an epoch. The number
+ * of authentication failures are tracked here within time periods
+ * determined by the server. If the user exceeds some threshold the account
+ * is automatically locked to prevent brute force attacks.
+ *
+ * @return the number of authentication failures within an epoch
+ */
+ int getFailuresInEpoch();
+
+ /**
+ * Checks to see if this profile is active.
+ */
+ boolean isActive();
+
+ /**
+ * Gets the profile's activation key.
+ */
+ String getActivationKey();
+
+ /**
+ * Get's the safehausTokenPin value for this account.
+ */
+ String getTokenPin();
+
+ /**
+ * Get's the static password for this account.
+ */
+ byte[] getPassword();
+
+
+ String getNotifyBy();
+}
Added: directory/trunks/triplesec/sms/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/sms/pom.xml?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/sms/pom.xml (added)
+++ directory/trunks/triplesec/sms/pom.xml Tue Dec 12 07:23:31 2006
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.safehaus.triplesec</groupId>
+ <artifactId>build</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>triplesec-sms</artifactId>
+ <name>Triplesec SMS API</name>
+ <description>
+ Short Message Service API for Triplesec Server
+ </description>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.0-rc3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.8</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/ClickatellSmsSessionFactoryTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/AbstractSmsSession.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/AbstractSmsSession.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/AbstractSmsSession.java (added)
+++ directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/AbstractSmsSession.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,128 @@
+/*
+ * 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.safehaus.sms;
+
+
+/**
+ * An abstract SmsSession where everything except the sendMessage method is implemented.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public abstract class AbstractSmsSession implements SmsSession
+{
+ /** the session identifier associated with this SmsSession */
+ private String sessionId;
+ /** the SMS message transport type associated with this SmsSession */
+ private SmsTransportType transport;
+ /** the user account associated with this SmsSession */
+ private String user;
+ /** the application identifier associated with this SmsSession */
+ private String applicationId;
+ /** flag used to toggle keep alive aspect of this SmsSession */
+ private boolean isKeepAliveEnabled;
+
+
+ public String getSessionId()
+ {
+ return sessionId;
+ }
+
+
+ /**
+ * Sets the session identifier for this SmsSession instance.
+ *
+ * @param sessionId the session identifier
+ */
+ protected void setSessionId( String sessionId )
+ {
+ this.sessionId = sessionId;
+ }
+
+
+ public SmsTransportType getTransport()
+ {
+ return transport;
+ }
+
+
+ /**
+ * Sets the transport type for this SmsSession instance.
+ *
+ * @param transport the transport type used by this session
+ */
+ protected void setTransport( SmsTransportType transport )
+ {
+ this.transport = transport;
+ }
+
+
+ public String getUser()
+ {
+ return user;
+ }
+
+
+ /**
+ * Sets the user that is associated with this SmsSession instance.
+ *
+ * @param user the user account associated with this SmsSession
+ */
+ protected void setUser( String user )
+ {
+ this.user = user;
+ }
+
+
+ public String getApplicationId()
+ {
+ return applicationId;
+ }
+
+
+ /**
+ * Sets the application identifier associated with this SmsSession instance.
+ *
+ * @param applicationId the application identifier associated with this SmsSession instance
+ */
+ protected void setApplicationId( String applicationId )
+ {
+ this.applicationId = applicationId;
+ }
+
+
+ public boolean isKeepAliveEnabled()
+ {
+ return isKeepAliveEnabled;
+ }
+
+
+ /**
+ * Sets whether or not this SmsSession will be kept alive by the implementation or it
+ * will time out.
+ *
+ * @param isKeepAliveEnabled true means the session is preserved, false means it could
+ * time out at any point in time unless immediately used.
+ */
+ protected void setKeepAliveEnabled( boolean isKeepAliveEnabled )
+ {
+ this.isKeepAliveEnabled = isKeepAliveEnabled;
+ }
+}
Added: directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/Carrier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/Carrier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/Carrier.java (added)
+++ directory/trunks/triplesec/sms/src/main/java/org/safehaus/sms/Carrier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,123 @@
+/*
+ * 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.safehaus.sms;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Supported carriers.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class Carrier
+{
+ public static final Carrier ATT = new Carrier( "AT&T", 31001 );
+ public static final Carrier CINGULAR = new Carrier( "Cingular", 31002 );
+ public static final Carrier VERIZON = new Carrier( "Verizon", 31003 );
+ public static final Carrier T_MOBILE = new Carrier( "T-Mobile", 31004 );
+ public static final Carrier SPRINT = new Carrier( "Sprint", 31005 );
+ public static final Carrier NEXTEL = new Carrier( "Nextel", 31007 );
+ public static final List ALL_CARRIERS;
+ public static final List ALL_CARRIER_STRINGS;
+ public static final Map CARRIER_CODE_MAP;
+
+ static
+ {
+ Map codeMap = new HashMap( 6 );
+ List carriers = new ArrayList( 6 );
+ List carrierStrings = new ArrayList( 6 );
+
+ carriers.add( ATT );
+ carrierStrings.add( ATT.toString() );
+ codeMap.put( ATT.getName(), new Integer( ATT.getValue()) );
+
+ carriers.add( CINGULAR );
+ carrierStrings.add( CINGULAR.toString() );
+ codeMap.put( CINGULAR.getName(), new Integer( CINGULAR.getValue()) );
+
+ carriers.add( VERIZON );
+ carrierStrings.add( VERIZON.toString() );
+ codeMap.put( VERIZON.getName(), new Integer( VERIZON.getValue()) );
+
+ carriers.add( T_MOBILE );
+ carrierStrings.add( T_MOBILE.toString() );
+ codeMap.put( T_MOBILE.getName(), new Integer( T_MOBILE.getValue()) );
+
+ carriers.add( SPRINT );
+ carrierStrings.add( SPRINT.toString() );
+ codeMap.put( SPRINT.getName(), new Integer( SPRINT.getValue()) );
+
+ carriers.add( NEXTEL );
+ carrierStrings.add( NEXTEL.toString() );
+ codeMap.put( NEXTEL.getName(), new Integer( NEXTEL.getValue()) );
+
+ /* add more here */
+
+ ALL_CARRIERS = Collections.unmodifiableList( carriers );
+ ALL_CARRIER_STRINGS = Collections.unmodifiableList( carrierStrings );
+ CARRIER_CODE_MAP = Collections.unmodifiableMap( codeMap );
+ }
+
+ private final String name;
+ private final int value;
+
+
+ private Carrier( String name, int value )
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public int getValue()
+ {
+ return value;
+ }
+
+
+ public String toString()
+ {
+ return name;
+ }
+
+
+ public static int getCarrierCode( String carrierName )
+ {
+ Integer integer = ( Integer ) CARRIER_CODE_MAP.get( carrierName );
+ if ( integer == null )
+ {
+ throw new IllegalArgumentException( "Unkown carrier name: " + carrierName );
+ }
+
+ return integer.intValue();
+ }
+}