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

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

Introduction

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

Prototype

public static SecurityContext createEmptyContext() 

Source Link

Document

Delegates the creation of a new, empty context to the configured strategy.

Usage

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext studentSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("opiskelija", "password"));
    return securityContext;
}

From source file:io.pivotal.cla.security.Login.java

public static Authentication loginAs(User user) {
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    UserAuthentication authentication = new UserAuthentication(user);
    context.setAuthentication(authentication);
    SecurityContextHolder.setContext(context);
    return authentication;
}

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext teacherSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("opettaja", "password"));
    return securityContext;
}

From source file:fi.helsinki.opintoni.security.TestSecurityContext.java

public static SecurityContext hybridUserSecurityContext() {
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("hybriduser", "password"));
    return securityContext;
}

From source file:org.jasig.springframework.security.portlet.context.NullPortletSecurityContextRepository.java

@Override
public SecurityContext loadContext(PortletRequestResponseHolder requestResponseHolder) {
    return SecurityContextHolder.createEmptyContext();
}

From source file:io.pivotal.cla.security.WithClaAuthorUserFactory.java

@Override
public SecurityContext createSecurityContext(WithClaAuthorUser user) {
    User adminUser = create();/*  ww  w  . j  ava 2s .  c  o m*/
    UserAuthentication auth = new UserAuthentication(adminUser);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(auth);
    return context;
}

From source file:io.pivotal.cla.security.WithAdminUserFactory.java

@Override
public SecurityContext createSecurityContext(WithAdminUser user) {
    User adminUser = create();/*from  w  w  w  .  j a v  a2 s . c om*/
    UserAuthentication auth = new UserAuthentication(adminUser);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(auth);
    return context;
}

From source file:samples.WithCustomUserSecurityContextFactory.java

public SecurityContext createSecurityContext(WithCustomUser customUser) {
    SecurityContext context = SecurityContextHolder.createEmptyContext();

    User principal = new User();
    principal.setEmail(customUser.email());
    principal.setFirstName(customUser.firstName());
    principal.setLastName(customUser.lastName());
    principal.setId(customUser.id());//from   w  ww .  j  av  a 2s .c om
    Authentication auth = new UsernamePasswordAuthenticationToken(principal, "password",
            AuthorityUtils.createAuthorityList("ROLE_USER"));
    context.setAuthentication(auth);
    return context;
}

From source file:com.application.utils.RequestHolderApplicationServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    SecurityContextHolder.setContext(SecurityContextHolder.createEmptyContext());

    RequestHolder.setRequest(request);// ww  w . j  a  v a  2s  .  c  om

    super.service(request, response);

    // We remove the request from the thread local, there's no reason to keep it once the work is done
    RequestHolder.clean();

    SecurityContextHolder.clearContext();
}

From source file:io.pivotal.cla.security.WithSigningUserFactory.java

@Override
public SecurityContext createSecurityContext(WithSigningUser user) {
    User principal = create();/*from   w w  w.jav  a2s. com*/
    principal.setAdminAccessRequested(user.requestedAdmin());
    UserAuthentication auth = new UserAuthentication(principal);
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(auth);
    return context;
}