Example usage for javax.security.auth.login AppConfigurationEntry getLoginModuleName

List of usage examples for javax.security.auth.login AppConfigurationEntry getLoginModuleName

Introduction

In this page you can find the example usage for javax.security.auth.login AppConfigurationEntry getLoginModuleName.

Prototype

public String getLoginModuleName() 

Source Link

Document

Get the class name of the configured LoginModule .

Usage

From source file:com.adito.core.CoreJAASConfiguration.java

/**
 * Add a new configuration entry./*  w w w. j a  va2  s . c  o m*/
 * 
 * @param name name
 * @param entry entry
 */
public void addAppConfigurationEntry(String name, AppConfigurationEntry entry) {
    if (log.isInfoEnabled())
        log.info("Adding new entry for '" + name + "' [" + entry.getLoginModuleName()
                + "' to JAAS configuration ");
    List l = (List) entries.get(name);
    if (l == null) {
        l = new ArrayList();
        entries.put(name, l);
    }
    l.add(entry);
}

From source file:gov.nih.nci.caintegrator.application.registration.RegistrationServiceImpl.java

/**
 * {@inheritDoc}/*from   w w w  .j  a v  a 2s. c  o  m*/
 */
@Override
@SuppressWarnings("unchecked")
public Map<String, String> getLdapContextParams() {
    Map<String, String> ldapContextParams = new HashMap<String, String>();
    XMLLoginConfigImpl config = retrieveConfigFile();
    if (config == null) {
        return ldapContextParams;
    }
    AppConfigurationEntry[] entries = config.getAppConfigurationEntry("caintegrator");
    for (AppConfigurationEntry entry : entries) {
        if (StringUtils.containsIgnoreCase(entry.getLoginModuleName(), "ldap")) {
            Map<String, String> entryMap = (Map<String, String>) entry.getOptions();
            for (String entryKey : entryMap.keySet()) {
                ldapContextParams.put(entryKey, entryMap.get(entryKey));
            }
        }
    }
    return ldapContextParams;
}

From source file:org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModuleConfigurator.java

public PropertiesLoginModuleConfigurator(String entryName, String brokerEtc) throws Exception {
    if (entryName == null || entryName.length() == 0) {
        entryName = "activemq";
    }//from  ww w.  j a  v  a  2s .  c o m

    Configuration securityConfig = Configuration.getConfiguration();
    AppConfigurationEntry[] entries = securityConfig.getAppConfigurationEntry(entryName);

    if (entries == null || entries.length == 0) {
        throw ActiveMQMessageBundle.BUNDLE.failedToLoadSecurityConfig();
    }

    int entriesInspected = 0;
    for (AppConfigurationEntry entry : entries) {
        entriesInspected++;
        if (entry.getLoginModuleName().equals(PropertiesLoginModule.class.getName())) {
            String userFileName = (String) entry.getOptions().get(USER_FILE_PROP_NAME);
            String roleFileName = (String) entry.getOptions().get(ROLE_FILE_PROP_NAME);

            File etcDir = new File(brokerEtc);
            File userFile = new File(etcDir, userFileName);
            File roleFile = new File(etcDir, roleFileName);

            if (!userFile.exists()) {
                throw ActiveMQMessageBundle.BUNDLE.failedToLoadUserFile(brokerEtc + userFileName);
            }

            if (!roleFile.exists()) {
                throw ActiveMQMessageBundle.BUNDLE.failedToLoadRoleFile(brokerEtc + roleFileName);
            }

            Configurations configs = new Configurations();
            userBuilder = configs.propertiesBuilder(userFile);
            roleBuilder = configs.propertiesBuilder(roleFile);
            userConfig = userBuilder.getConfiguration();
            roleConfig = roleBuilder.getConfiguration();

            String roleHeader = roleConfig.getLayout().getHeaderComment();
            String userHeader = userConfig.getLayout().getHeaderComment();

            if (userHeader == null) {
                if (userConfig.isEmpty()) {
                    //clean and reset header
                    userConfig.clear();
                    userConfig.setHeader(LICENSE_HEADER);
                }
            }

            if (roleHeader == null) {
                if (roleConfig.isEmpty()) {
                    //clean and reset header
                    roleConfig.clear();
                    roleConfig.setHeader(LICENSE_HEADER);
                }
            }
            return;
        }
    }

    if (entriesInspected == entries.length) {
        throw ActiveMQMessageBundle.BUNDLE.failedToFindLoginModuleEntry(entryName);
    }
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

public static void authWithConfig(String appName, Configuration config) {
    try {//from  w  ww.  jav a  2s  . co  m
        if (config != null) {
            logger.info(
                    "Getting AppConfigrationEntry[] for appName=" + appName + ", config=" + config.toString());
            AppConfigurationEntry[] entries = config.getAppConfigurationEntry(appName);
            if (entries != null) {
                logger.info("Got " + entries.length + "  AppConfigrationEntry elements for appName=" + appName);
                for (AppConfigurationEntry appEntry : entries) {
                    logger.info("APP_ENTRY:getLoginModuleName()=" + appEntry.getLoginModuleName());
                    logger.info("APP_ENTRY:getControlFlag()=" + appEntry.getControlFlag());
                    logger.info("APP_ENTRY.getOptions()=" + appEntry.getOptions());
                }
            }

            LoginContext loginContext = new LoginContext(appName, new Subject(), null, config);
            logger.info("Login in for appName=" + appName);
            loginContext.login();
            logger.info("Principals after login=" + loginContext.getSubject().getPrincipals());
            logger.info("UserGroupInformation.loginUserFromSubject(): appName=" + appName + ", principals="
                    + loginContext.getSubject().getPrincipals());

            UserGroupInformation ugi = MiscUtil.createUGIFromSubject(loginContext.getSubject());
            if (ugi != null) {
                MiscUtil.setUGILoginUser(ugi, loginContext.getSubject());
            }

            // UserGroupInformation.loginUserFromSubject(loginContext
            // .getSubject());
            logger.info("POST UserGroupInformation.loginUserFromSubject UGI="
                    + UserGroupInformation.getLoginUser());
        }
    } catch (Throwable t) {
        logger.fatal("Error logging as appName=" + appName + ", config=" + config.toString() + ", error="
                + t.getMessage());
    }
}

From source file:org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded.java

public static void adaptClientSecurityDomain(SecurityDomain sd) {
    AppConfigurationEntry[] entries = sd.getAppConfigurationEntries();
    if (entries != null) {
        for (int i = 0; i < entries.length; i++) {
            AppConfigurationEntry entry = entries[i];
            if ("org.jboss.security.ClientLoginModule".equals(entry.getLoginModuleName())) {
                Map<String, ?> opts = entry.getOptions();
                Map<String, Object> newOpts = new HashMap<String, Object>(opts);
                newOpts.put("multi-threaded", "false");
                entries[i] = new AppConfigurationEntry(entry.getLoginModuleName(), entry.getControlFlag(),
                        entry.getOptions());
            }/*  w w  w  . j av a 2  s .  c  om*/
        }
    }
}