use of javax.security.auth.login.AppConfigurationEntry in project spring-security by spring-projects.
the class JaasApiIntegrationFilterTests method onBeforeTests.
// ~ Methods
// ========================================================================================================
@Before
public void onBeforeTests() throws Exception {
this.filter = new JaasApiIntegrationFilter();
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
authenticatedSubject = new Subject();
authenticatedSubject.getPrincipals().add(new Principal() {
public String getName() {
return "principal";
}
});
authenticatedSubject.getPrivateCredentials().add("password");
authenticatedSubject.getPublicCredentials().add("username");
callbackHandler = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
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);
}
}
}
};
testConfiguration = new Configuration() {
public void refresh() {
}
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, new HashMap<String, String>()) };
}
};
LoginContext ctx = new LoginContext("SubjectDoAsFilterTest", authenticatedSubject, callbackHandler, testConfiguration);
ctx.login();
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.AppConfigurationEntry in project spring-security by spring-projects.
the class DefaultJaasAuthenticationProviderTests method setUp.
@Before
public void setUp() throws Exception {
Configuration configuration = mock(Configuration.class);
publisher = mock(ApplicationEventPublisher.class);
log = mock(Log.class);
provider = new DefaultJaasAuthenticationProvider();
provider.setConfiguration(configuration);
provider.setApplicationEventPublisher(publisher);
provider.setAuthorityGranters(new AuthorityGranter[] { new TestAuthorityGranter() });
provider.afterPropertiesSet();
AppConfigurationEntry[] aces = new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap()) };
when(configuration.getAppConfigurationEntry(provider.getLoginContextName())).thenReturn(aces);
token = new UsernamePasswordAuthenticationToken("user", "password");
ReflectionTestUtils.setField(provider, "log", log);
}
use of javax.security.auth.login.AppConfigurationEntry in project OpenAM by OpenRock.
the class ConfiguredSocialAuthServices method filterConfigs.
@Override
protected Set<String> filterConfigs(Set<String> namedConfigs, ServiceConfig parentConfig, String realm, SSOToken adminToken) {
AMAuthenticationManager authMgr;
try {
authMgr = new AMAuthenticationManager(adminToken, realm);
} catch (AMConfigurationException e) {
debug.warning("Could not load authentication manager for realm: " + realm, e);
return Collections.EMPTY_SET;
}
Set<String> configs = new TreeSet<String>();
for (String config : namedConfigs) {
try {
ServiceConfig authConfig = parentConfig.getSubConfig(config);
Set<String> chainConfig = (Set<String>) authConfig.getAttributes().get(AMAuthConfigUtils.ATTR_NAME);
AppConfigurationEntry[] chain = AMAuthConfigUtils.parseValues(chainConfig.iterator().next());
for (int i = 0; i < chain.length; i++) {
if (getType(authMgr, chain[i]).equals(OAUTH2_TYPE)) {
// There's an OAuth2 module in the chain, so this could be a social authn chain
configs.add(config);
}
}
} catch (SMSException e) {
if (debug.messageEnabled()) {
debug.message("Not using auth chain as couldn't get config: " + config, e);
}
} catch (SSOException e) {
if (debug.warningEnabled()) {
debug.warning("Invalid SSO Token when trying to get config for " + config, e);
}
}
}
return configs;
}
use of javax.security.auth.login.AppConfigurationEntry in project OpenAM by OpenRock.
the class AMConfiguration method parseXMLConfig.
private AppConfigurationEntry[] parseXMLConfig(String xmlConfig, String name, AMAuthenticationManager amAM) throws SMSException, SSOException {
// parse the auth configuration
AppConfigurationEntry[] entries = AMAuthConfigUtils.parseValues(xmlConfig);
if (entries == null) {
return null;
}
int len = entries.length;
// App config entry to return
AppConfigurationEntry[] ret = new AppConfigurationEntry[len];
// module parameters for the organization
for (int i = 0; i < len; i++) {
String className = entries[i].getLoginModuleName();
int dot = className.lastIndexOf('.');
String moduleName = className;
if (dot != -1) {
moduleName = className.substring(dot + 1);
}
AMAuthenticationInstance instance = amAM.getAuthenticationInstance(moduleName);
if (instance == null) {
return null;
}
// retrieve all attributes
Map attribs = instance.getAttributeValues();
if (attribs == null) {
return null;
}
if (dot == -1) {
// className is only an instance name here.
String type = instance.getType();
className = getLoginModuleClassName(type);
}
// add those user defined options.
// NOTE : user defined options are key/String value
// but our attributes are key/Set of String value
attribs.putAll(entries[i].getOptions());
attribs.put(ISAuthConstants.MODULE_INSTANCE_NAME, moduleName);
// construct AppConfigurationEntry
ret[i] = new AppConfigurationEntry(className, entries[i].getControlFlag(), attribs);
// add listener for this Login module
addServiceListener(AuthUtils.getModuleServiceName(instance.getType()), name);
}
return ret;
}
use of javax.security.auth.login.AppConfigurationEntry in project OpenAM by OpenRock.
the class AMConfiguration method getServiceBasedConfig.
/**
* Returns service based authentication configuration. This method will
* read the authentication configuration XML for the service, parse the
* XML to return the <code>AppConfigurationEntry[]</code>.
*
* @param orgDN Organization DN.
* @param service Service name.
* @param name Authentication configuration name.
* @return Array of <code>AppConfigurationEntry</code>.
*/
private AppConfigurationEntry[] getServiceBasedConfig(String orgDN, String service, String name, AMAuthenticationManager amAM) {
if (debug.messageEnabled()) {
debug.message("ServiceBasedConfig, START " + orgDN + "|" + service + ", name = " + name);
}
if (service == null) {
return null;
}
try {
Map attributeDataMap = AMAuthConfigUtils.getNamedConfig(service, orgDN, getAdminToken());
Set xmlConfigValue = (Set) attributeDataMap.get(AMAuthConfigUtils.ATTR_NAME);
String xmlConfig = null;
if (xmlConfigValue != null && !xmlConfigValue.isEmpty()) {
xmlConfig = (String) xmlConfigValue.iterator().next();
}
if (xmlConfig == null) {
// return null now for security concern
return null;
}
AppConfigurationEntry[] ret = parseXMLConfig(xmlConfig, name, amAM);
if (debug.messageEnabled()) {
debug.message("serviceBased, add SM listener on " + service);
}
addServiceListener("iPlanetAMAuthConfiguration", name);
if (debug.messageEnabled()) {
debug.message("ServiceBasedConfig, return config " + service + ", org=" + orgDN);
}
return ret;
} catch (Exception e) {
// got exception, return null config
debug.error("getServiceBasedConfig " + service + "|" + orgDN, e);
return null;
}
}
Aggregations