harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r500939 - in /harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/javax/security/auth/kerberos/ main/java/common/org/apache/harmony/auth/internal/kerberos/v5/ test/java/common/org/apache/harmony/auth/tests/javax/security/auth...
Date Mon, 29 Jan 2007 05:31:09 GMT
Author: smishura
Date: Sun Jan 28 21:31:03 2007
New Revision: 500939

URL: http://svn.apache.org/viewvc?view=rev&rev=500939
Log:
KerberosPrincipal: default values are initialized in one place

Modified:
    harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
    harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
    harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java?view=diff&rev=500939&r1=500938&r2=500939
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
Sun Jan 28 21:31:03 2007
@@ -21,12 +21,11 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.security.AccessController;
 import java.security.Principal;
-import java.security.PrivilegedAction;
 import java.util.StringTokenizer;
 
-import org.apache.harmony.auth.internal.kerberos.v5.KrbConfig;
+import org.apache.harmony.auth.internal.kerberos.v5.KerberosException;
+import org.apache.harmony.auth.internal.kerberos.v5.KrbClient;
 import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
 import org.apache.harmony.auth.internal.nls.Messages;
 import org.apache.harmony.security.asn1.ASN1StringType;
@@ -47,9 +46,6 @@
 
     public static final int KRB_NT_UID = 5;
 
-    // default realm 
-    private static String defaultRealm;
-    
     // the full name of principal
     private transient String name;
 
@@ -82,36 +78,14 @@
             this.name = name;
         } else {
             // look for default realm name
-            // TODO sync defaultRealm update
-            if (defaultRealm == null) {
-                defaultRealm = AccessController
-                        .doPrivileged(new PrivilegedAction<String>() {
-                            public String run() {
-
-                                String v = System
-                                        .getProperty("java.security.krb5.realm"); //$NON-NLS-1$
-                                if (v == null) {
-                                    // look in config files 
-                                    KrbConfig config = null;
-                                    try {
-                                        config = KrbConfig.getSystemConfig();
-                                    } catch (IOException e) {
-                                        // ignore
-                                    }
-                                    if (config != null) {
-                                        v = config.getValue("libdefaults", //$NON-NLS-1$
-                                                "default_realm"); //$NON-NLS-1$
-                                    }
-                                }
-                                return v;
-                            }
-                        });
-
+            try {
+                realm = KrbClient.getRealm();
+            } catch (KerberosException e) {
+                throw new IllegalArgumentException(e);
             }
 
-            realm = defaultRealm;
             if (realm != null) {
-                this.name = name + '@' + defaultRealm;
+                this.name = name + '@' + realm;
             } else {
                 this.name = name;
             }

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java?view=diff&rev=500939&r1=500938&r2=500939
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/KrbClient.java
Sun Jan 28 21:31:03 2007
@@ -48,12 +48,21 @@
 
     private static final int BUF_SIZE = 1024;
 
+    private static boolean isInitialized = false;
+    
     private KrbClient() {
         // no objects
     }
 
+    public static synchronized String getRealm() throws KerberosException {
+        if (!isInitialized) {
+            setEnv();
+        }
+        return realm;
+    }
+
     private static void setEnv() throws KerberosException {
-        if (kdc != null && realm != null) {
+        if (isInitialized) {
             return;
         }
 
@@ -64,8 +73,24 @@
             // both properties should be set or unset together
             throw new KerberosException();//FIXME message
         } else if (kdc == null && realm == null) {
+
             // reading config from configuration file 'krb5.conf'
-            throw new KerberosException();//FIXME not yet implemented
+            KrbConfig config = null;
+            try {
+                config = KrbConfig.getSystemConfig();
+            } catch (IOException e) {
+                throw new KerberosException(e.getMessage());
+            }
+
+            if (config == null) {
+                // no config file was found
+                throw new KerberosException();//FIXME err msg
+            }
+            realm = config.getValue("libdefaults", //$NON-NLS-1$
+                    "default_realm"); //$NON-NLS-1$
+            
+            //TODO set KDC
+            return;
         }
 
         int pos = kdc.indexOf(':');
@@ -73,6 +98,8 @@
             port = Integer.parseInt(kdc.substring(pos + 1));
             kdc = kdc.substring(0, pos);
         }
+        
+        isInitialized = true;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java?view=diff&rev=500939&r1=500938&r2=500939
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
Sun Jan 28 21:31:03 2007
@@ -170,6 +170,27 @@
     public static class DefaultRealm_SystemProperty {
         public static void main(String[] av) {
 
+            // case 1: unset 'kdc' and set 'realm'
+            TestUtils.setSystemProperty(KRB5_REALM_SYS_PROP, "some_value");
+            TestUtils.setSystemProperty(KRB5_KDC_SYS_PROP, null);
+            try {
+                new KerberosPrincipal("name");
+                fail("No expected IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+            } finally {
+                TestUtils.setSystemProperty(KRB5_REALM_SYS_PROP, null);
+            }
+
+            // case 2: set 'kdc' and unset 'realm' sys.props
+            TestUtils.setSystemProperty(KRB5_KDC_SYS_PROP, "some_value");
+            try {
+                new KerberosPrincipal("name");
+                fail("No expected IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+            } finally {
+                TestUtils.setSystemProperty(KRB5_KDC_SYS_PROP, null);
+            }
+            
             String testRealm = "This_is_test_realm";
 
             System.setProperty(KRB5_REALM_SYS_PROP, testRealm);



Mime
View raw message