Author: erodriguez
Date: Fri Oct 29 23:45:01 2004
New Revision: 56029

Added:
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/PrincipalNameType.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Realm.java
Log:
Principal identifier supporting value objects.

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/PrincipalNameType.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/PrincipalNameType.java
    Fri Oct 29 23:45:01 2004
@@ -0,0 +1,81 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.messages.value;
+
+import java.util.*;
+
+public final class PrincipalNameType implements Comparable {
+
+       /**
+        * Enumeration elements are constructed once upon class loading.
+        * Order of appearance here determines the order of compareTo.
+        */
+       public static final PrincipalNameType KRB_NT_UNKNOWN = 
+               new PrincipalNameType(0, "unknown name type");
+       public static final PrincipalNameType KRB_NT_PRINCIPAL = 
+               new PrincipalNameType(1, "user principal name type");
+       public static final PrincipalNameType KRB_NT_SRV_INST = 
+               new PrincipalNameType(2, "service and other unique instance 
(krbtgt) name type");
+       public static final PrincipalNameType KRB_NT_SRV_HST = 
+               new PrincipalNameType(3, "service with host name as instance 
(telnet, rcommands)");
+       public static final PrincipalNameType KRB_NT_SRV_XHST = 
+               new PrincipalNameType(4, "service with host name as instance 
(telnet, rcommands) name type");
+       public static final PrincipalNameType KRB_NT_UID = 
+               new PrincipalNameType(5, "unique ID name type");
+       public static final PrincipalNameType KRB_NT_X500_PRINCIPAL =  
+               new PrincipalNameType(6, "nt x500 principal; encoded X.509 
Distinguished name [RFC 2253]");
+       
+       public String toString() {
+               return _fName + " (" + _fOrdinal + ")";
+       }
+
+       public int compareTo(Object that) {
+               return _fOrdinal - ((PrincipalNameType) that)._fOrdinal;
+       }
+
+       public static PrincipalNameType getTypeByOrdinal(int type) {
+               for (int i = 0; i < fValues.length; i++)
+                       if (fValues[i]._fOrdinal == type)
+                               return fValues[i];
+               return KRB_NT_UNKNOWN;
+       }
+       
+       public int getOrdinal() {
+               return _fOrdinal;
+       }
+
+       /// PRIVATE /////
+       private final String _fName;
+       private final int    _fOrdinal;
+
+       /**
+        * Private constructor prevents construction outside of this class.
+        */
+       private PrincipalNameType(int ordinal, String name) {
+               _fOrdinal = ordinal;
+               _fName    = name;
+       }
+
+       /**
+        * These two lines are all that's necessary to export a List of VALUES.
+        */
+       private static final PrincipalNameType[] fValues = {KRB_NT_UNKNOWN, 
KRB_NT_PRINCIPAL, 
+                       KRB_NT_SRV_INST, KRB_NT_SRV_HST, KRB_NT_SRV_XHST, 
KRB_NT_UID, KRB_NT_X500_PRINCIPAL};
+       // VALUES needs to be located here, otherwise illegal forward reference
+       public static final List VALUES = 
Collections.unmodifiableList(Arrays.asList(fValues));
+}
+

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Realm.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/messages/value/Realm.java
        Fri Oct 29 23:45:01 2004
@@ -0,0 +1,41 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.kerberos.messages.value;
+
+public class Realm {
+
+       private String _name;
+
+       public Realm(String name) {
+               _name = name;
+       }
+       
+       public boolean equals(Object o) {
+               if (this == o)
+                       return true;
+               if (!(o instanceof Realm))
+                       return false;
+
+               Realm that = (Realm) o;
+               return this._name.equals(that._name);
+       }
+
+       public String toString() {
+               return _name;
+       }
+}
+

Reply via email to