1 46 47 package org.mr.kernel.security.authentication; 48 49 import org.mr.MantaAgent; 50 import org.apache.commons.logging.LogFactory; 51 import org.apache.commons.logging.Log; 52 53 import javax.security.auth.login.Configuration ; 54 import javax.security.auth.login.AppConfigurationEntry ; 55 import java.util.Map ; 56 import java.util.HashMap ; 57 58 import org.mr.kernel.security.MantaSecurityException; 59 import org.mr.kernel.security.SecurityConfigurationPaths; 60 import org.mr.kernel.security.SecurityConstants; 61 62 71 public class AuthenticationConfiguration extends Configuration implements SecurityConfigurationPaths, SecurityConstants { 72 AppConfigurationEntry [] _appConfigurationEntries; 73 private Log _logger; 74 75 79 public AuthenticationConfiguration() throws MantaSecurityException { 80 init(); 81 } 82 83 private void init() throws MantaSecurityException { 84 String currentACLConfigurationInUse = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(ACL + "." + ACL_CONFIGURATION_IN_USE); 85 if (currentACLConfigurationInUse == null){ 86 if (getLogger().isErrorEnabled()) 87 getLogger().error("[init] Unable to find configuration parameter: " + ACL + "." + ACL_CONFIGURATION_IN_USE); 88 throw new MantaSecurityException("Unable to find configuration parameter: " + ACL + "." + ACL_CONFIGURATION_IN_USE); 89 } 90 91 String ldapIp = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(ACL_CONFIGURATIONS + "." + currentACLConfigurationInUse + "." + IP, DEFAULT_LDAP_IP); 93 int ldapPort = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getIntProperty(ACL_CONFIGURATIONS + "." + currentACLConfigurationInUse + "." + PORT, DEFAULT_LDAP_PORT); 94 95 String pathToUsers = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(ACL_CONFIGURATIONS + "." + currentACLConfigurationInUse + "." + PATH_TO_USERS); 96 if (pathToUsers == null){ 97 if (getLogger().isErrorEnabled()) 98 getLogger().error("[init] Unable to find configuration parameter: " + ACL_CONFIGURATIONS + "." + currentACLConfigurationInUse + "." + PATH_TO_USERS); 99 throw new MantaSecurityException("Unable to find configuration parameter: " + ACL_CONFIGURATIONS + "." + currentACLConfigurationInUse + "." + PATH_TO_USERS); 100 } 101 102 _appConfigurationEntries = new AppConfigurationEntry [1]; 104 String loginModuleName = MantaAgent.getInstance().getSingletonRepository().getConfigManager().getStringProperty(AUTHENTICATION_LOGIN_MODULE_NAME, DEFAULT_LOGIN_MODULE_NAME); 105 AppConfigurationEntry.LoginModuleControlFlag controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; 106 Map options = new HashMap (); 107 String userProviderUrl = "ldap://" + ldapIp + ":" + ldapPort + "/" + pathToUsers; 108 options.put("user.provider.url", userProviderUrl); 109 options.put("group.provider.url", userProviderUrl); 110 _appConfigurationEntries[0] = new AppConfigurationEntry (loginModuleName, controlFlag, options); 111 } 112 113 123 public AppConfigurationEntry [] getAppConfigurationEntry(String applicationName) { 124 return _appConfigurationEntries; 125 } 126 127 131 public synchronized void refresh() { 132 try { 133 init(); 134 } 135 catch (MantaSecurityException e) { 136 if (getLogger().isErrorEnabled()) 137 getLogger().error("[refresh] " + e.getMessage()); 138 } 139 } 140 141 146 public Log getLogger(){ 147 if (_logger == null){ 148 _logger = LogFactory.getLog(getClass().getName()); 149 } 150 return _logger; 151 } 152 } 153 | Popular Tags |