directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 56209 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc
Date Mon, 01 Nov 2004 05:21:11 GMT
Author: erodriguez
Date: Sun Oct 31 21:21:10 2004
New Revision: 56209

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/KdcConfiguration.java
Log:
Implementation of properties-based KDC configuration.

Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/KdcConfiguration.java
==============================================================================
--- (empty file)
+++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/kdc/KdcConfiguration.java
Sun Oct 31 21:21:10 2004
@@ -0,0 +1,179 @@
+/*
+ *   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.kdc;
+
+import org.apache.kerberos.crypto.encryption.*;
+
+import java.io.*;
+import java.util.*;
+
+import javax.security.auth.kerberos.*;
+
+public class KdcConfiguration {
+	
+	private static final int DEFAULT_PORT = 88;
+	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(new FileInputStream("kerberos.properties"));
+	    } 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;
+	}
+	
+	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()]);
+	}
+}
+

Mime
View raw message