use of javax.security.auth.login.Configuration in project atlas by apache.
the class AtlasPamAuthenticationProvider method init.
private void init() {
try {
AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry(loginModuleName, controlFlag, options);
AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry };
Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>();
appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries);
Configuration configuration = new InMemoryConfiguration(appConfigurationEntriesOptions);
jaasAuthenticationProvider.setConfiguration(configuration);
UserAuthorityGranter authorityGranter = new UserAuthorityGranter();
UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[] { authorityGranter };
jaasAuthenticationProvider.setAuthorityGranters(authorityGranters);
jaasAuthenticationProvider.afterPropertiesSet();
} catch (Exception e) {
LOG.error("Failed to init PAM Authentication", e);
}
}
use of javax.security.auth.login.Configuration in project tomcat70 by apache.
the class JAASRealm method getConfig.
/**
* Load custom JAAS Configuration
*/
protected Configuration getConfig() {
try {
if (jaasConfigurationLoaded) {
return jaasConfiguration;
}
synchronized (this) {
if (configFile == null) {
jaasConfigurationLoaded = true;
return null;
}
URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile);
URI uri = resource.toURI();
@SuppressWarnings("unchecked") Class<Configuration> sunConfigFile = (Class<Configuration>) Class.forName("com.sun.security.auth.login.ConfigFile");
Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class);
Configuration config = constructor.newInstance(uri);
this.jaasConfiguration = config;
this.jaasConfigurationLoaded = true;
return this.jaasConfiguration;
}
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
} catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
} catch (SecurityException ex) {
throw new RuntimeException(ex);
} catch (InstantiationException ex) {
throw new RuntimeException(ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
} catch (IllegalArgumentException ex) {
throw new RuntimeException(ex);
} catch (InvocationTargetException ex) {
throw new RuntimeException(ex.getCause());
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
}
use of javax.security.auth.login.Configuration in project storm by nathanmarz.
the class AuthUtils method GetConfiguration.
/**
* Construct a JAAS configuration object per storm configuration file
* @param storm_conf Storm configuration
* @return JAAS configuration object
*/
public static Configuration GetConfiguration(Map storm_conf) {
Configuration login_conf = null;
// find login file configuration from Storm configuration
String loginConfigurationFile = (String) storm_conf.get("java.security.auth.login.config");
if ((loginConfigurationFile != null) && (loginConfigurationFile.length() > 0)) {
try {
URI config_uri = new File(loginConfigurationFile).toURI();
login_conf = Configuration.getInstance("JavaLoginConfig", new URIParameter(config_uri));
} catch (NoSuchAlgorithmException ex1) {
if (ex1.getCause() instanceof FileNotFoundException)
throw new RuntimeException("configuration file " + loginConfigurationFile + " could not be found");
else
throw new RuntimeException(ex1);
} catch (Exception ex2) {
throw new RuntimeException(ex2);
}
}
return login_conf;
}
use of javax.security.auth.login.Configuration in project spring-security by spring-projects.
the class JaasApiIntegrationFilterTests method onBeforeTests.
@BeforeEach
public void onBeforeTests() throws Exception {
this.filter = new JaasApiIntegrationFilter();
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.authenticatedSubject = new Subject();
this.authenticatedSubject.getPrincipals().add(() -> "principal");
this.authenticatedSubject.getPrivateCredentials().add("password");
this.authenticatedSubject.getPublicCredentials().add("username");
this.callbackHandler = (callbacks) -> {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName("user");
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword("password".toCharArray());
} else if (callback instanceof TextInputCallback) {
// ignore
} else {
throw new UnsupportedCallbackException(callback, "Unrecognized Callback " + callback);
}
}
};
this.testConfiguration = new Configuration() {
@Override
public void refresh() {
}
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, new HashMap<>()) };
}
};
LoginContext ctx = new LoginContext("SubjectDoAsFilterTest", this.authenticatedSubject, this.callbackHandler, this.testConfiguration);
ctx.login();
this.token = new JaasAuthenticationToken("username", "password", AuthorityUtils.createAuthorityList("ROLE_ADMIN"), ctx);
// just in case someone forgot to clear the context
SecurityContextHolder.clearContext();
}
use of javax.security.auth.login.Configuration in project spring-security by spring-projects.
the class DefaultJaasAuthenticationProviderTests method setUp.
@BeforeEach
public void setUp() throws Exception {
Configuration configuration = mock(Configuration.class);
this.publisher = mock(ApplicationEventPublisher.class);
this.log = mock(Log.class);
this.provider = new DefaultJaasAuthenticationProvider();
this.provider.setConfiguration(configuration);
this.provider.setApplicationEventPublisher(this.publisher);
this.provider.setAuthorityGranters(new AuthorityGranter[] { new TestAuthorityGranter() });
this.provider.afterPropertiesSet();
AppConfigurationEntry[] aces = new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap()) };
given(configuration.getAppConfigurationEntry(this.provider.getLoginContextName())).willReturn(aces);
this.token = new UsernamePasswordAuthenticationToken("user", "password");
ReflectionTestUtils.setField(this.provider, "log", this.log);
}
Aggregations