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:ubic.gemma.testing.BaseSpringContextTest.java

/**
 * @throws Exception/*w  ww .  j a va  2s. c  om*/
 */
@Override
final public void afterPropertiesSet() throws Exception {
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    hibernateSupport.setSessionFactory(this.getBean(SessionFactory.class));

    CompassUtils.deleteCompassLocks();

    this.authenticationTestingUtil = new AuthenticationTestingUtil();
    this.authenticationTestingUtil.setUserManager(this.getBean(UserManager.class));

    runAsAdmin();

}

From source file:ubic.gemma.util.AbstractSpringAwareCLI.java

/** check username and password. */
void authenticate() {

    /*//from   ww w  .  j  a  va2 s  . c o  m
     * Allow security settings (authorization etc) in a given context to be passed into spawned threads
     */
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);

    ManualAuthenticationService manAuthentication = ctx.getBean(ManualAuthenticationService.class);
    if (hasOption('u') && hasOption('p')) {
        username = getOptionValue('u');
        password = getOptionValue('p');

        if (StringUtils.isBlank(username)) {
            System.err.println("Not authenticated. Username was blank");
            log.debug("Username=" + username);
            bail(ErrorCode.AUTHENTICATION_ERROR);
        }

        if (StringUtils.isBlank(password)) {
            System.err.println("Not authenticated. You didn't enter a password");
            bail(ErrorCode.AUTHENTICATION_ERROR);
        }

        boolean success = manAuthentication.validateRequest(username, password);
        if (!success) {
            System.err.println("Not authenticated. Make sure you entered a valid username (got '" + username
                    + "') and/or password");
            bail(ErrorCode.AUTHENTICATION_ERROR);
        } else {
            log.info("Logged in as " + username);
        }
    } else {
        log.info("Logging in as anonymous guest with limited privileges");
        manAuthentication.authenticateAnonymously();
    }

}

From source file:ubic.gemma.util.AbstractSpringAwareCLI.java

/**
 * check if using test or production contexts
 *///from  www  .  j  ava 2s  .c om
protected void createSpringContext() {

    ctx = SpringContextUtil.getApplicationContext(hasOption("testing"), false /* webapp */,
            getAdditionalSpringConfigLocations());

    /*
     * Guarantee that the security settings are uniform throughout the application (all threads).
     */
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}

From source file:ubic.gemma.web.listener.StartupListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    StartupListener.log.info("Initializing Gemma web context ...");
    StopWatch sw = new StopWatch();
    sw.start();/*from  ww  w  .  j  a  v  a2s .  c  o m*/

    // call Spring's context ContextLoaderListener to initialize
    // all the context files specified in web.xml
    super.contextInitialized(event);

    ServletContext servletContext = event.getServletContext();

    Map<String, Object> config = this.initializeConfiguration(servletContext);

    this.loadTheme(servletContext, config);

    this.loadVersionInformation(config);

    this.loadTrackerInformation(config);

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);

    servletContext.setAttribute(Constants.CONFIG, config);

    this.initializeHomologene(ctx);

    this.configureScheduler(ctx);

    sw.stop();

    double time = sw.getTime() / 1000.00;
    StartupListener.log.info("Initialization of Gemma Spring web context in " + time + " s ");
}