Search in sources :

Example 21 with AppConfigurationEntry

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();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IOException(java.io.IOException) Subject(javax.security.auth.Subject) TextInputCallback(javax.security.auth.callback.TextInputCallback) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) TextInputCallback(javax.security.auth.callback.TextInputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) LoginContext(javax.security.auth.login.LoginContext) JaasAuthenticationToken(org.springframework.security.authentication.jaas.JaasAuthenticationToken) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Principal(java.security.Principal) Before(org.junit.Before)

Example 22 with AppConfigurationEntry

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);
}
Also used : DefaultJaasAuthenticationProvider(org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProvider) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) Log(org.apache.commons.logging.Log) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Before(org.junit.Before)

Example 23 with AppConfigurationEntry

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;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Set(java.util.Set) TreeSet(java.util.TreeSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) TreeSet(java.util.TreeSet) AMConfigurationException(com.sun.identity.authentication.config.AMConfigurationException) SSOException(com.iplanet.sso.SSOException) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 24 with AppConfigurationEntry

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;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with AppConfigurationEntry

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;
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Aggregations

AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)74 HashMap (java.util.HashMap)30 Configuration (javax.security.auth.login.Configuration)25 Map (java.util.Map)13 Test (org.junit.Test)11 Subject (javax.security.auth.Subject)10 LoginContext (javax.security.auth.login.LoginContext)10 SSOException (com.iplanet.sso.SSOException)7 SMSException (com.sun.identity.sm.SMSException)7 HashSet (java.util.HashSet)7 JaasRealm (org.apache.karaf.jaas.config.JaasRealm)7 Set (java.util.Set)6 LoginException (javax.security.auth.login.LoginException)5 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 LoginModuleControlFlag (javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 File (java.io.File)3 Principal (java.security.Principal)3