01: /*
02: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
03: */
04: package com.technoetic.xplanner.security.module.jaas;
05:
06: import java.util.Map;
07: import java.util.MissingResourceException;
08:
09: import com.technoetic.xplanner.security.LoginModule;
10: import com.technoetic.xplanner.security.module.ConfigurationException;
11: import com.technoetic.xplanner.security.module.LoginModuleFactory;
12: import com.technoetic.xplanner.security.module.LoginSupport;
13:
14: public class JaasLoginModuleAdapterFactory implements
15: LoginModuleFactory {
16: static final String JAAS_USER_PRINCIPAL_CLASS_NAME_KEY = "jaas.principalClass";
17: static final String JAAS_LOGIN_MODULE_CLASS_NAME_KEY = "jaas.loginModuleClass";
18: private LoginSupport support;
19:
20: public JaasLoginModuleAdapterFactory(LoginSupport loginSupport) {
21: this .support = loginSupport;
22: }
23:
24: public LoginModule newInstance(Map options)
25: throws ConfigurationException {
26: Class principalClass = getClassFromName(options,
27: JAAS_USER_PRINCIPAL_CLASS_NAME_KEY);
28: return new JaasLoginModuleAdapter(support,
29: getJAASLoginModule(options), principalClass, options);
30: }
31:
32: private Class getClassFromName(Map options, String property) {
33: String className = (String) options.get(property);
34: if (className == null) {
35: Exception cause = new MissingResourceException(
36: "Missing property", this .getClass().getName(),
37: property);
38: throw new ConfigurationException(cause);
39: }
40: Class aClass;
41: try {
42: aClass = Class.forName(className);
43: } catch (ClassNotFoundException e) {
44: throw new ConfigurationException(e);
45: }
46: return aClass;
47: }
48:
49: private javax.security.auth.spi.LoginModule getJAASLoginModule(
50: Map options) {
51: Class loginModuleClass = getClassFromName(options,
52: JAAS_LOGIN_MODULE_CLASS_NAME_KEY);
53: try {
54: return (javax.security.auth.spi.LoginModule) loginModuleClass
55: .newInstance();
56: } catch (Exception e) {
57: throw new ConfigurationException(e);
58: }
59: }
60:
61: }
|