You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/11/04 04:34:05 UTC

svn commit: rev 56561 - incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/kdc

Author: akarasulu
Date: Wed Nov  3 19:34:05 2004
New Revision: 56561

Modified:
   incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/kdc/KdcConfiguration.java
Log:
Changes ...

 o reformated code 
 o added new constructor to take a Properties object



Modified: incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/kdc/KdcConfiguration.java
==============================================================================
--- incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/kdc/KdcConfiguration.java	(original)
+++ incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/kdc/KdcConfiguration.java	Wed Nov  3 19:34:05 2004
@@ -16,14 +16,16 @@
  */
 package org.apache.kerberos.kdc;
 
-import org.apache.kerberos.crypto.encryption.*;
 
-import java.io.*;
+import java.io.IOException;
 import java.util.*;
+import javax.security.auth.kerberos.KerberosPrincipal;
 
-import javax.security.auth.kerberos.*;
+import org.apache.kerberos.crypto.encryption.EncryptionType;
 
-public class KdcConfiguration {
+
+public class KdcConfiguration
+{
     /** the defaults resource file */
     private static final String DEFAULTS = "kerberos.properties";
 
@@ -33,170 +35,240 @@
     private static final String KDC_PRINCIPAL = "kdc.principal";
 
 
-	private static final int DEFAULT_PORT  = 88;
-	private static final int CHANGEPW_PORT = 464;
-	private static final int BUFFER_SIZE   = 1024;
-	private static final int MINUTE        = 1000 * 60;
-	
-	private Properties       _properties = new Properties();
-	private EncryptionType[] _encryptionTypes;
-
-
-    public KdcConfiguration() {
-	    try {
-            _properties.load( getClass().getResourceAsStream( DEFAULTS ) );
-	    } catch (IOException e) {
-	    	e.printStackTrace();
-	    }
-	    
-	    prepareEncryptionTypes();
-	}
-	
-	public String getPrimaryRealm() {
-		String key = KDC_PRIMARY_REALM;
-		return (String)_properties.get(key);
-	}
-	
-	public KerberosPrincipal getKdcPrincipal() {
-		String key = KDC_PRINCIPAL;
-		return new KerberosPrincipal((String)_properties.get(key));
-	}
-	
-	public String getKerberosKeysLocation() {
-		String key = "kdc.keys.location";
-		return (String)_properties.get(key);
-	}
-	
-	public EncryptionType[] getEncryptionTypes() {
-		return _encryptionTypes;
-	}
-	
-	public Hashtable getProperties() {
-		// Request that the krb5key value be returned as binary 
-		_properties.put("java.naming.ldap.attributes.binary", "krb5Key");
-		
-		return _properties;
-	}
-	
-	public long getClockSkew() {
-		String key = "kdc.allowable.clockskew";
-		if (_properties.containsKey(key)) {
-			return MINUTE * Long.parseLong((String)_properties.get(key));
-		}
-		return MINUTE * 5;
-	}
-	
-	public long getMaximumTicketLifetime() {
-		String key = "tgs.maximum.ticket.lifetime";
-		if (_properties.containsKey(key)) {
-			return MINUTE * Long.parseLong((String)_properties.get(key));
-		}
-		return MINUTE * 1440;
-	}
-	
-	public long getMaximumRenewableLifetime() {
-		String key = "tgs.maximum.renewable.lifetime";
-		if (_properties.containsKey(key)) {
-			return MINUTE * Long.parseLong((String)_properties.get(key));
-		}
-		return MINUTE * 10080;
-	}
-	
-	public int getDefaultPort() {
-		String key = "kdc.default.port";
-		if (_properties.containsKey(key)) {
-			return Integer.parseInt((String)_properties.get(key));
-		}
-		return DEFAULT_PORT;
-	}
-	
-	public int getBufferSize() {
-		String key = "kdc.buffer.size";
-		if (_properties.containsKey(key)) {
-			return Integer.parseInt((String)_properties.get(key));
-		}
-		return BUFFER_SIZE;
-	}
-	
-	public boolean isPaEncTimestampRequired() {
-		String key = "kdc.pa.enc.timestamp.required";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public boolean isEmptyAddressesAllowed() {
-		String key = "tgs.empty.addresses.allowed";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public boolean isForwardableAllowed() {
-		String key = "tgs.forwardable.allowed";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public boolean isProxiableAllowed() {
-		String key = "tgs.proxiable.allowed";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public boolean isPostdateAllowed() {
-		String key = "tgs.postdate.allowed";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public boolean isRenewableAllowed() {
-		String key = "tgs.renewable.allowed";
-		if (_properties.containsKey(key)) {
-			return "true".equalsIgnoreCase((String)_properties.get(key));
-		}
-		return true;
-	}
-	
-	public int getChangepwPort() {
-		String key = "changepw.default.port";
-		if (_properties.containsKey(key)) {
-			return Integer.parseInt((String)_properties.get(key));
-		}
-		return CHANGEPW_PORT;
-	}
-	
-	public KerberosPrincipal getChangepwPrincipal() {
-		String key = "changepw.principal";
-		return new KerberosPrincipal((String)_properties.get(key));
-	}
-	
-	private void prepareEncryptionTypes() {
-		String key = "kdc.encryption.types";
-	    String[] encryptionTypes = ((String)_properties.get(key)).split("\\s");
-	    
-	    List encTypes = new ArrayList();
-	    
-	    for (int i = 0;i < encryptionTypes.length; i++) {
-	    	String enc = encryptionTypes[i];
-	    	Iterator it = EncryptionType.VALUES.iterator();
-	    	while (it.hasNext()) {
-	    		EncryptionType type = (EncryptionType)it.next();
-	    		if (type.toString().equalsIgnoreCase(enc)) {
-	    			encTypes.add(type);
-	    		}
-	    	}
-	    }
-	    
-	    _encryptionTypes = (EncryptionType[])encTypes.toArray(new EncryptionType[encTypes.size()]);
-	}
+    private static final int DEFAULT_PORT = 88;
+    private static final int CHANGEPW_PORT = 464;
+    private static final int BUFFER_SIZE = 1024;
+    private static final int MINUTE = 1000 * 60;
+
+    private final Properties properties = new Properties();
+    private EncryptionType[] _encryptionTypes;
+
+
+    public KdcConfiguration()
+    {
+        loadDefaults();
+        prepareEncryptionTypes();
+    }
+
+
+    public KdcConfiguration( Properties properties )
+    {
+        loadDefaults();
+        this.properties.putAll( properties );
+        prepareEncryptionTypes();
+    }
+
+
+    private void loadDefaults()
+    {
+        try
+        {
+            this.properties.load( getClass().getResourceAsStream( DEFAULTS ) );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    public String getPrimaryRealm()
+    {
+        String key = KDC_PRIMARY_REALM;
+        return ( String ) properties.get( key );
+    }
+
+
+    public KerberosPrincipal getKdcPrincipal()
+    {
+        String key = KDC_PRINCIPAL;
+        return new KerberosPrincipal( ( String ) properties.get( key ) );
+    }
+
+
+    public String getKerberosKeysLocation()
+    {
+        String key = "kdc.keys.location";
+        return ( String ) properties.get( key );
+    }
+
+
+    public EncryptionType[] getEncryptionTypes()
+    {
+        return _encryptionTypes;
+    }
+
+
+    public Hashtable getProperties()
+    {
+        // Request that the krb5key value be returned as binary
+        properties.put( "java.naming.ldap.attributes.binary", "krb5Key" );
+
+        return properties;
+    }
+
+
+    public long getClockSkew()
+    {
+        String key = "kdc.allowable.clockskew";
+        if ( properties.containsKey( key ) )
+        {
+            return MINUTE * Long.parseLong( ( String ) properties.get( key ) );
+        }
+        return MINUTE * 5;
+    }
+
+
+    public long getMaximumTicketLifetime()
+    {
+        String key = "tgs.maximum.ticket.lifetime";
+        if ( properties.containsKey( key ) )
+        {
+            return MINUTE * Long.parseLong( ( String ) properties.get( key ) );
+        }
+        return MINUTE * 1440;
+    }
+
+
+    public long getMaximumRenewableLifetime()
+    {
+        String key = "tgs.maximum.renewable.lifetime";
+        if ( properties.containsKey( key ) )
+        {
+            return MINUTE * Long.parseLong( ( String ) properties.get( key ) );
+        }
+        return MINUTE * 10080;
+    }
+
+
+    public int getDefaultPort()
+    {
+        String key = "kdc.default.port";
+        if ( properties.containsKey( key ) )
+        {
+            return Integer.parseInt( ( String ) properties.get( key ) );
+        }
+        return DEFAULT_PORT;
+    }
+
+
+    public int getBufferSize()
+    {
+        String key = "kdc.buffer.size";
+        if ( properties.containsKey( key ) )
+        {
+            return Integer.parseInt( ( String ) properties.get( key ) );
+        }
+        return BUFFER_SIZE;
+    }
+
+
+    public boolean isPaEncTimestampRequired()
+    {
+        String key = "kdc.pa.enc.timestamp.required";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public boolean isEmptyAddressesAllowed()
+    {
+        String key = "tgs.empty.addresses.allowed";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public boolean isForwardableAllowed()
+    {
+        String key = "tgs.forwardable.allowed";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public boolean isProxiableAllowed()
+    {
+        String key = "tgs.proxiable.allowed";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public boolean isPostdateAllowed()
+    {
+        String key = "tgs.postdate.allowed";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public boolean isRenewableAllowed()
+    {
+        String key = "tgs.renewable.allowed";
+        if ( properties.containsKey( key ) )
+        {
+            return "true".equalsIgnoreCase( ( String ) properties.get( key ) );
+        }
+        return true;
+    }
+
+
+    public int getChangepwPort()
+    {
+        String key = "changepw.default.port";
+        if ( properties.containsKey( key ) )
+        {
+            return Integer.parseInt( ( String ) properties.get( key ) );
+        }
+        return CHANGEPW_PORT;
+    }
+
+
+    public KerberosPrincipal getChangepwPrincipal()
+    {
+        String key = "changepw.principal";
+        return new KerberosPrincipal( ( String ) properties.get( key ) );
+    }
+
+
+    private void prepareEncryptionTypes()
+    {
+        String key = "kdc.encryption.types";
+        String[] encryptionTypes = ( ( String ) properties.get( key ) ).split( "\\s" );
+
+        List encTypes = new ArrayList();
+
+        for ( int i = 0; i < encryptionTypes.length; i++ )
+        {
+            String enc = encryptionTypes[i];
+            Iterator it = EncryptionType.VALUES.iterator();
+            while ( it.hasNext() )
+            {
+                EncryptionType type = ( EncryptionType ) it.next();
+                if ( type.toString().equalsIgnoreCase( enc ) )
+                {
+                    encTypes.add( type );
+                }
+            }
+        }
+
+        _encryptionTypes = ( EncryptionType[] ) encTypes.toArray( new EncryptionType[encTypes.size()] );
+    }
 }