Example usage for javax.security.auth.login Configuration getConfiguration

List of usage examples for javax.security.auth.login Configuration getConfiguration

Introduction

In this page you can find the example usage for javax.security.auth.login Configuration getConfiguration.

Prototype

public static Configuration getConfiguration() 

Source Link

Document

Get the installed login Configuration.

Usage

From source file:org.jasig.cas.authentication.handler.support.JaasAuthenticationHandler.java

public JaasAuthenticationHandler() {
    Assert.notNull(Configuration.getConfiguration(),
            "Static Configuration cannot be null. Did you remember to specify \"java.security.auth.login.config\"?");
}

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

@SuppressWarnings({ "unchecked", "rawtypes" })
private XMLLoginConfigImpl retrieveConfigFile() {
    try {//w  w w.j  a va 2s .c  o m
        XMLLoginConfigImpl config = (XMLLoginConfigImpl) java.security.AccessController
                .doPrivileged(new java.security.PrivilegedAction() {
                    @Override
                    public Object run() {
                        return Configuration.getConfiguration();
                    }
                });
        return config;
    } catch (RuntimeException e) {
        return null;
    }
}

From source file:com.adito.activedirectory.ActiveDirectoryUserDatabase.java

private void addJAASConfiguration() {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("client", "TRUE");
    parameters.put("debug", String.valueOf(logger.isDebugEnabled()).toUpperCase());
    parameters.put("useSubjectCredsOnly", "FALSE");
    parameters.put("useTicketCache", "FALSE");
    parameters.put("refreshKrb5Config", "TRUE");

    AppConfigurationEntry entry = new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, parameters);
    CoreJAASConfiguration config = (CoreJAASConfiguration) Configuration.getConfiguration();
    config.addAppConfigurationEntry(ActiveDirectoryUserDatabase.class.getName(), entry);
}

From source file:org.wso2.carbon.mediator.kerberos.KerberosMediator.java

/**
 * Extracts data from login conf and sets the values
 * @param msgCtx// w  w w  .  ja  v a  2  s  .co  m
 */
private void extractDataFromLoginConf(MessageContext msgCtx) {

    //Read configuration again if type is keytab and config is not configFile
    if (StringUtils.isNotEmpty(getLoginContextName())) {
        Configuration.setConfiguration(null);
    }

    if (StringUtils.isNotEmpty(getLoginConfig())) {
        String loginConfigPath = CONFIG_PATH + getLoginConfig();
        File file = new File(loginConfigPath);
        if (file.exists()) {
            System.setProperty(KerberosConstants.JAAS_CONFIG_PROPERTY, file.getAbsolutePath());
            AppConfigurationEntry entries[] = Configuration.getConfiguration()
                    .getAppConfigurationEntry(getLoginContextName());
            if (entries != null && entries.length != 0) {
                Map<String, ?> options = entries[0].getOptions();
                //Evaluate and set the values for username, password and keytab elements
                setElements(options, msgCtx);
            } else {
                handleException("Could not find specified service account.", msgCtx);
            }
        } else {
            handleException("Could not find the login configuration.", msgCtx);
        }
    } else if (StringUtils.isNotEmpty(getLoginContextName())) {
        String loginConfigPath = DEFAULT_LOGIN_CONFIG_PATH;
        File file = new File(loginConfigPath);
        if (file.exists()) {
            System.setProperty(KerberosConstants.JAAS_CONFIG_PROPERTY, file.getAbsolutePath());
            AppConfigurationEntry entries[] = Configuration.getConfiguration()
                    .getAppConfigurationEntry(getLoginContextName());
            if (entries != null && entries.length != 0) {
                Map<String, ?> options = entries[0].getOptions();
                //Evaluate and set the values for username, password and keytab elements
                setElements(options, msgCtx);
            } else {
                handleException("Could not find specified service account.", msgCtx);
            }
        } else {
            handleException("Could not find the login configuration.", msgCtx);
        }
    } else {
        //Set username.
        if (getClientPrincipal() != null && StringUtils.isNotEmpty(getClientPrincipal().getKeyValue())) {
            this.clientPrincipalValue = getClientPrincipal().getKeyValue();
        }

        //Set password.
        if (this.password != null && StringUtils.isNotEmpty(this.password.getKeyValue())) {
            this.passwordValue = this.password.getKeyValue();
        }
    }
}

From source file:org.wso2.carbon.mediator.kerberos.KerberosMediator.java

/**
 * Set JASS configuration with the principal and keyTab.
 *///w w w . j a  v a 2  s. c  o  m
private void setJASSConfiguration(boolean useKeyTab, MessageContext msgCtx) {

    Map<String, Object> optionSet = new HashMap<>();
    if (StringUtils.isNotEmpty(getLoginConfig())) {
        String loginConfigPath = CONFIG_PATH + getLoginConfig();
        File file = new File(loginConfigPath);
        if (file.exists()) {
            System.setProperty(KerberosConstants.JAAS_CONFIG_PROPERTY, file.getAbsolutePath());
            AppConfigurationEntry entries[] = Configuration.getConfiguration()
                    .getAppConfigurationEntry(getLoginContextName());
            if (entries != null && entries.length != 0) {
                Map<String, ?> options = entries[0].getOptions();
                for (String s : options.keySet()) {
                    optionSet.put(s, options.get(s));
                }
            } else {
                handleException("Could not find specified service account.", msgCtx);
            }
        } else {
            handleException("Could not find the login configuration.", msgCtx);
        }
    } else if (StringUtils.isNotEmpty(getLoginContextName())) {
        String loginConfigPath = DEFAULT_LOGIN_CONFIG_PATH;
        File file = new File(loginConfigPath);
        if (file.exists()) {
            System.setProperty(KerberosConstants.JAAS_CONFIG_PROPERTY, file.getAbsolutePath());
            AppConfigurationEntry entries[] = Configuration.getConfiguration()
                    .getAppConfigurationEntry(getLoginContextName());
            if (entries != null && entries.length != 0) {
                Map<String, ?> options = entries[0].getOptions();
                for (String s : options.keySet()) {
                    optionSet.put(s, options.get(s));
                }
            } else {
                handleException("Could not find specified service account.", msgCtx);
            }
        } else {
            handleException("Could not find the login configuration.", msgCtx);
        }
    }

    optionSet.put(KerberosConstants.IS_INITIATOR, "true");
    optionSet.put(KerberosConstants.PRINCIPAL, clientPrincipalValue);
    optionSet.put(KerberosConstants.USE_KEYTAB, String.valueOf(useKeyTab));
    if (useKeyTab) {
        File keyTabFile = new File(keytabPath);
        if (keyTabFile.exists()) {
            optionSet.put(KerberosConstants.KEYTAB, keyTabFile.getAbsolutePath());
        } else {
            handleException("Could not find the keytab file " + keytabPath + " in the location " + CONFIG_PATH,
                    msgCtx);
        }
    } else {
        optionSet.put(KerberosConstants.KEYTAB, null);
    }
    if (log.isDebugEnabled()) {
        optionSet.put(KerberosConstants.DEBUG, "true");
    }
    final Map<String, Object> finalOptionSet = optionSet;
    Configuration.setConfiguration(new Configuration() {
        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {

            return new AppConfigurationEntry[] {
                    new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
                            AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, finalOptionSet) };
        }
    });
}

From source file:org.acegisecurity.providers.jaas.JaasAuthenticationProvider.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull(loginConfig, "loginConfig must be set on " + getClass());
    Assert.hasLength(loginContextName, "loginContextName must be set on " + getClass());

    configureJaas(loginConfig);//from  w w  w .  j  av  a2 s. c o m

    Assert.notNull(Configuration.getConfiguration(),
            "As per http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/login/Configuration.html "
                    + "\"If a Configuration object was set via the Configuration.setConfiguration method, then that object is "
                    + "returned. Otherwise, a default Configuration object is returned\". Your JRE returned null to "
                    + "Configuration.getConfiguration().");
}

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  w  w  w  . ja  va  2 s  .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.atlas.security.InMemoryJAASConfiguration.java

private InMemoryJAASConfiguration(Properties prop) {
    parent = Configuration.getConfiguration();
    initialize(prop);
}

From source file:org.eclipse.ecr.runtime.api.login.LoginComponent.java

@Override
public void activate(ComponentContext context) throws Exception {
    // setup the nuxeo login configuration
    Configuration parentConfig = null;
    try {/*from   ww  w.j a  va 2s.c om*/
        parentConfig = Configuration.getConfiguration();
    } catch (Exception e) {
        // do nothing - this can happen if default configuration provider
        // is not correctly configured
        // for examnple FileConfig fails if no config file was defined
    }
    config = new LoginConfiguration(this, parentConfig);
    Configuration.setConfiguration(config);
}

From source file:org.eclipse.gyrex.boot.internal.app.ServerApplication.java

private void startConsole() throws BundleException {
    // enable SSH console
    // TODO: might want to use ConfigAdmin?
    final EnvironmentInfo environmentInfo = BootActivator.getEnvironmentInfo();
    if (null == environmentInfo.getProperty("osgi.console.ssh")) {
        // set default ssh port
        environmentInfo.setProperty("osgi.console.ssh", String.valueOf(Platform.getInstancePort(3122)));
    }//from   w  w  w  .j a  v a 2 s . c o  m
    if (null == environmentInfo.getProperty("ssh.custom.publickeys.auth")) {
        // enable custom ssh authentication
        environmentInfo.setProperty("ssh.custom.publickeys.auth", "true");
    }
    if (startBundle(BSN_EQUINOX_CONSOLE_SSH, false)) {
        try {
            final Object authenticator = BootActivator.getInstance().getBundle().loadClass(
                    "org.eclipse.gyrex.boot.internal.ssh.InstanceLocationAuthorizedKeysFileAuthenticator")
                    .newInstance();
            BootActivator.getInstance().getServiceHelper().registerService(
                    "org.apache.sshd.server.PublickeyAuthenticator", authenticator, "Eclipse Gyrex",
                    "Equionx SSH Console authorized_keys support for Gyrex.", null, Integer.MAX_VALUE);
        } catch (final ClassNotFoundException e) {
            // ignore
        } catch (final LinkageError e) {
            // ignore
        } catch (final Exception e) {
            // error (but do not fail)
            LOG.warn("Unable to register authorized_keys file support for Equinox SSH Console. ", e);
        }

        // allow any combination of username/password in development mode
        if (Platform.inDevelopmentMode()) {
            final AppConfigurationEntry[] allowAny = new AppConfigurationEntry[] {
                    new AppConfigurationEntry("org.eclipse.gyrex.boot.console.jaas.AllowAnyUserLoginModule",
                            LoginModuleControlFlag.SUFFICIENT, new HashMap<String, Object>()) };
            final Configuration configuration = Configuration.getConfiguration();
            Configuration.setConfiguration(new Configuration() {

                @Override
                public AppConfigurationEntry[] getAppConfigurationEntry(final String name) {
                    final AppConfigurationEntry[] entry = configuration.getAppConfigurationEntry(name);
                    if (((entry == null) || (entry.length == 0)) && "equinox_console".equals(name))
                        return allowAny;
                    return entry;
                }
            });
        }
    }
}