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.pentaho.platform.repository2.unified.webservices.jaxws.DefaultUnifiedRepositoryJaxwsWebServiceIT.java

@Before
public void setUp() throws Exception {
    super.setUp();

    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);

    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);

    String address = "http://localhost:9000/repo";
    Endpoint.publish(address, new DefaultUnifiedRepositoryJaxwsWebService(repo));

    Service service = Service.create(new URL("http://localhost:9000/repo?wsdl"),
            new QName("http://www.pentaho.org/ws/1.0", "unifiedRepository"));

    IUnifiedRepositoryJaxwsWebService repoWebService = service.getPort(IUnifiedRepositoryJaxwsWebService.class);

    // accept cookies to maintain session on server
    ((BindingProvider) repoWebService).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    // support streaming binary data
    ((BindingProvider) repoWebService).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,
            8192);//from   www  .j  av a 2  s  .com
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) repoWebService).getBinding();
    binding.setMTOMEnabled(true);

    repo = new UnifiedRepositoryToWebServiceAdapter(repoWebService);

}

From source file:org.pentaho.test.platform.web.http.api.DirectoryResourceIT.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);
}

From source file:org.pentaho.test.platform.web.http.api.DirectoryResourceIT.java

@AfterClass
public static void afterClass() {
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}

From source file:org.pentaho.test.platform.web.http.api.DirectoryResourceIT.java

@Before
public void beforeTest() throws PlatformInitializationException {
    mp = new MicroPlatform();
    // used by DefaultPentahoJackrabbitAccessControlHelper
    mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
    mp.defineInstance(ITenantManager.class, tenantManager);
    mp.define(ITenant.class, Tenant.class);
    mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
    mp.defineInstance(IRoleAuthorizationPolicyRoleBindingDao.class, roleBindingDaoTarget);
    mp.defineInstance("tenantedUserNameUtils", tenantedUserNameUtils);
    mp.defineInstance("tenantedRoleNameUtils", tenantedRoleNameUtils);
    mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
    mp.define(IRoleAuthorizationPolicyRoleBindingDao.class, RoleAuthorizationPolicy.class, Scope.GLOBAL);
    mp.define(ITenantManager.class, RepositoryTenantManager.class, Scope.GLOBAL);
    mp.defineInstance("singleTenantAdminAuthorityName", new String("Administrator"));
    mp.defineInstance("RepositoryFileProxyFactory",
            new RepositoryFileProxyFactory(this.testJcrTemplate, this.repositoryFileDao));

    DefaultRepositoryVersionManager defaultRepositoryVersionManager = new DefaultRepositoryVersionManager();
    defaultRepositoryVersionManager.setPlatformMimeResolver(new NameBaseMimeResolver());
    mp.defineInstance(IRepositoryVersionManager.class, defaultRepositoryVersionManager);
    UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
    userDetailsService.setUserRoleDao(userRoleDao);
    List<String> systemRoles = new ArrayList<String>();
    systemRoles.add("Admin");
    List<String> extraRoles = Arrays.asList(new String[] { "Authenticated", "Anonymous" });
    String adminRole = "Admin";

    userRoleListService = new UserRoleDaoUserRoleListService(userRoleDao, userDetailsService,
            tenantedUserNameUtils, systemRoles, extraRoles, adminRole);
    ((UserRoleDaoUserRoleListService) userRoleListService).setUserRoleDao(userRoleDao);
    ((UserRoleDaoUserRoleListService) userRoleListService).setUserDetailsService(userDetailsService);

    mp.defineInstance(IUserRoleListService.class, userRoleListService);
    mp.start();/*from   w  w w.j  av  a2  s . co m*/
    logout();
    startupCalled = true;
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
}

From source file:org.pentaho.test.platform.web.http.api.RepositoryResourceIT.java

@Before
public void beforeTest() throws Exception {
    repositoryBase.setUp();/*from w  w w  .j  av  a2 s .co  m*/
    repositoryBase.getMp().define(IPluginManager.class, DefaultPluginManager.class, Scope.GLOBAL);
    repositoryBase.getMp().defineInstance(IPluginResourceLoader.class, new PluginResourceLoader() {
        protected PluginClassLoader getOverrideClassloader() {
            return new PluginClassLoader(
                    new File(TestResourceLocation.TEST_RESOURCES + "/PluginResourceTest/system/test-plugin"),
                    this);
        }
    });
    repositoryBase.getMp().define(IPluginProvider.class, TestPlugin.class, Scope.GLOBAL);
    PentahoSystem.get(IPluginManager.class).reload();
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);

    repositoryBase.loginAsRepositoryAdmin();

    mainTenant_1 = repositoryBase.createTenant(repositoryBase.getSystemTenant(), MAIN_TENANT_1);
    repositoryBase.createUser(mainTenant_1, "admin", "password",
            new String[] { repositoryBase.getTenantAdminRoleName() });

    repositoryBase.login("admin", mainTenant_1, new String[] { repositoryBase.getTenantAdminRoleName() });

    publicFolderPath = ClientRepositoryPaths.getPublicFolderPath().replaceAll("/", ":");
}

From source file:ubc.pavlab.aspiredb.cli.AbstractCLI.java

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

    /*/*from  w  w  w .  ja  v a 2  s .co  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:ubc.pavlab.aspiredb.server.BaseSpringContextTest.java

/**
 * @throws Exception//from w  w w. ja v a2  s . c o  m
 */
@Override
final public void afterPropertiesSet() throws Exception {
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    hibernateSupport.setSessionFactory(this.getBean(SessionFactory.class));

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

    runAsAdmin();
}

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

/**
 * check if using test or production contexts
 *///  w  ww  . j av  a  2 s .c o  m
protected void createSpringContext() {

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

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

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

/**
 * check username and password./*from ww  w  . j  a  v  a 2s.  co m*/
 */
private void authenticate() {

    /*
     * 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 (this.hasOption('u') && this.hasOption('p')) {
        username = this.getOptionValue('u');
        password = this.getOptionValue('p');

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

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

        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");
            exitwithError();
        } else {
            AbstractCLI.log.info("Logged in as " + username);
        }
    } else {
        AbstractCLI.log.info("Logging in as anonymous guest with limited privileges");
        manAuthentication.authenticateAnonymously();
    }

}

From source file:ubic.gemma.core.util.test.BaseSpringContextTest.java

@Override
final public void afterPropertiesSet() {
    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    hibernateSupport.setSessionFactory(this.getBean(SessionFactory.class));

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

    this.runAsAdmin();

}