Example usage for org.springframework.security.core.context SecurityContextHolder setStrategyName

List of usage examples for org.springframework.security.core.context SecurityContextHolder setStrategyName

Introduction

In this page you can find the example usage for org.springframework.security.core.context SecurityContextHolder setStrategyName.

Prototype

public static void setStrategyName(String strategyName) 

Source Link

Document

Changes the preferred strategy.

Usage

From source file:org.key2gym.client.Main.java

/**
 * The main method which performs all the task described in the class
 * description.// w  w w . j  a  va  2  s . c o m
 * 
 * @param args an array of arguments
 */
public static void main(String[] args) {

    /*
     * Configures the logger using 'etc/logging.properties' or the default
     * logging properties file.
     */
    try (InputStream input = new FileInputStream(PATH_LOGGING_PROPERTIES)) {
        PropertyConfigurator.configure(input);
    } catch (IOException ex) {
        try (InputStream input = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream(RESOURCE_DEFAULT_LOGGING_PROPERTIES)) {
            PropertyConfigurator.configure(input);

            /*
             * Notify that the default logging properties file has been
             * used.
             */
            logger.info("Could not load the logging properties file");
        } catch (IOException ex2) {
            throw new RuntimeException("Failed to initialize logging system", ex2);
        }
    }

    logger.info("Starting...");

    /*
     * Loads the built-in default properties file.
     */
    try (InputStream input = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(RESOURCE_DEFAULT_CLIENT_PROPERTIES)) {
        Properties defaultProperties = null;
        defaultProperties = new Properties();
        defaultProperties.load(input);
        properties.putAll(defaultProperties);
    } catch (IOException ex) {
        throw new RuntimeException("Failed to load the default client properties file", ex);
    }

    /*
     * Loads the local client properties file.
     */
    try (FileInputStream input = new FileInputStream(PATH_APPLICATION_PROPERTIES)) {
        Properties localProperties = null;
        localProperties = new Properties();
        localProperties.load(input);
        properties.putAll(localProperties);
    } catch (IOException ex) {
        if (logger.isEnabledFor(Level.DEBUG)) {
            logger.debug("Failed to load the client properties file", ex);
        } else {
            logger.info("Could not load the local client properties file");
        }

        /*
         * It's okay to start without the local properties file.
         */
    }

    logger.debug("Effective properties: " + properties);

    if (properties.containsKey(PROPERTY_LOCALE_COUNTRY) && properties.containsKey(PROPERTY_LOCALE_LANGUAGE)) {

        /*
         * Changes the application's locale.
         */
        Locale.setDefault(new Locale(properties.getProperty(PROPERTY_LOCALE_LANGUAGE),
                properties.getProperty(PROPERTY_LOCALE_COUNTRY)));

    } else {
        logger.debug("Using the default locale");
    }

    /*
     * Changes the application's L&F.
     */
    String ui = properties.getProperty(PROPERTY_UI);
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if (ui.equalsIgnoreCase(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
        logger.error("Failed to change the L&F:", ex);
    }

    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);

    // Loads the client application context
    context = new ClassPathXmlApplicationContext("META-INF/client.xml");

    logger.info("Started!");
    launchAndWaitMainFrame();
    logger.info("Shutting down!");

    context.close();
}

From source file:co.paralleluniverse.springframework.security.config.FiberSecurityContextHolderConfig.java

public FiberSecurityContextHolderConfig() {
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}

From source file:org.parancoe.plugins.security.SecureInterceptor.java

/**
 * Costructor. In the costructor strategy of SecurityContextHolder
 * has set./*w  w  w.j ava2 s  .  c  om*/
 *
 */
public SecureInterceptor() {

    SecurityContextHolder.setStrategyName(STRATEGY_CLASS_NAME);
    logger.info("SecureInterceptor set up");

}

From source file:jedai.business.JAuthorizationService.java

/**
 * initializes the strategy used by SpringSecurity
 *//* w  ww  . j  a  v a 2  s. com*/
public void init() {
    SecurityContextHolder.setStrategyName("jedai.business.JedaiSecurityContextHolderStrategy");
}

From source file:org.vaadin.spring.security.internal.SecurityContextVaadinRequestListener.java

public SecurityContextVaadinRequestListener() {
    logger.info("Initializing {}, setting SecurityContextHolder strategy to {}", getClass().getSimpleName(),
            SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
}

From source file:org.bremersee.common.spring.autoconfigure.SecurityAutoConfiguration.java

@PostConstruct
public void init() {
    // @formatter:off
    log.info("\n" // NOSONAR
            + "**********************************************************************\n"
            + "*  Security Auto Configuration                                       *\n"
            + "**********************************************************************\n"
            + "securityProperties = " + securityProperties + "\n"
            + "**********************************************************************");
    // @formatter:on

    if (StringUtils.isNotBlank(securityProperties.getContextHolderStrategyName())) {
        SecurityContextHolder.setStrategyName(securityProperties.getContextHolderStrategyName());
    }/*from ww  w .  j a v a  2 s . c  o m*/
}

From source file:org.opennms.poller.remote.Main.java

private void getAuthenticationInfo() throws InvocationTargetException, InterruptedException {
    if (m_uri == null) {
        throw new IllegalArgumentException("no URI specified!");
    } else if (m_uri.getScheme() == null) {
        throw new IllegalArgumentException("no URI scheme specified!");
    }/*from w  w  w  . j av  a 2 s  .c  o  m*/

    // Make sure that the URI is a valid value
    SpringExportSchemes.valueOf(m_uri.getScheme());

    if (SpringExportSchemes.rmi.toString().equals(m_uri.getScheme())) {
        // RMI doesn't have authentication
        return;
    }

    if (m_username == null) {
        // Display a screen where the username and password are entered
        final AuthenticationGui gui = createGui();
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                gui.createAndShowGui();
            }
        });

        /*
         * This call pauses on a {@link CountDownLatch} that is
         * signaled when the user hits the 'OK' button on the GroovyGui
         * screen.
         */
        AuthenticationBean auth = gui.getAuthenticationBean();

        m_username = auth.getUsername();
        m_password = auth.getPassword();
    }

    if (m_username != null) {
        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
        SecurityContextHolder.getContext()
                .setAuthentication(new UsernamePasswordAuthenticationToken(m_username, m_password));
    }
}

From source file:org.pentaho.di.repository.pur.PurRepositoryIT.java

protected void setUpUser() {
    StandaloneSession pentahoSession = new StandaloneSession(userInfo.getLogin());
    pentahoSession.setAuthenticated(userInfo.getLogin());
    pentahoSession.setAttribute(IPentahoSession.TENANT_ID_KEY, "/pentaho/" + EXP_TENANT);
    List<GrantedAuthority> authorities = new ArrayList<>(2);
    authorities.add(new SimpleGrantedAuthority("Authenticated"));
    authorities.add(new SimpleGrantedAuthority("acme_Authenticated"));
    final String password = "ignored"; //$NON-NLS-1$
    UserDetails userDetails = new User(userInfo.getLogin(), password, true, true, true, true, authorities);
    Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, password, authorities);
    // next line is copy of SecurityHelper.setPrincipal
    pentahoSession.setAttribute("SECURITY_PRINCIPAL", authentication);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
    PurRepositoryTestingUtils.setSession(pentahoSession, authentication);
    repositoryLifecyleManager.newTenant();
    repositoryLifecyleManager.newUser();
}

From source file:org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEERepositoryDirectoryIT.java

private void setUpUser() {
    StandaloneSession pentahoSession = new StandaloneSession(userInfo.getLogin());
    pentahoSession.setAuthenticated(userInfo.getLogin());
    pentahoSession.setAttribute(IPentahoSession.TENANT_ID_KEY, "/pentaho/" + EXP_TENANT);
    List<GrantedAuthority> authorities = new ArrayList<>(2);
    authorities.add(new SimpleGrantedAuthority("Authenticated"));
    authorities.add(new SimpleGrantedAuthority("acme_Authenticated"));
    final String password = "ignored"; //$NON-NLS-1$
    UserDetails userDetails = new User(userInfo.getLogin(), password, true, true, true, true, authorities);
    Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, password, authorities);
    // next line is copy of SecurityHelper.setPrincipal
    pentahoSession.setAttribute("SECURITY_PRINCIPAL", authentication);
    PentahoSessionHolder.setSession(pentahoSession);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    repositoryLifecyleManager.newTenant();
    repositoryLifecyleManager.newUser();
}

From source file:org.pentaho.platform.plugin.services.metadata.MetadataRepositoryLifecycleManagerIT.java

@BeforeClass
public static void beforeClass() throws Exception {
    System.setProperty(SYSTEM_PROPERTY, "MODE_GLOBAL");
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    FileUtils.deleteDirectory(new File("/tmp/jackrabbit-test-TRUNK"));
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}