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

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

Introduction

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

Prototype

public static void clearContext() 

Source Link

Document

Explicitly clears the context value from the current thread.

Usage

From source file:example.company.Application.java

/**
 * Pre-load the system with employees and items.
 *//* w  ww  . jav a 2  s .  com*/
@PostConstruct
public void init() {

    employeeRepository.save(new Employee("Bilbo", "Baggins", "thief"));
    employeeRepository.save(new Employee("Frodo", "Baggins", "ring bearer"));
    employeeRepository.save(new Employee("Gandalf", "the Wizard", "servant of the Secret Fire"));

    /**
     * Due to method-level protections on {@link example.company.ItemRepository}, the security context must be loaded
     * with an authentication token containing the necessary privileges.
     */
    SecurityUtils.runAs("system", "system", "ROLE_ADMIN");

    itemRepository.save(new Item("Sting"));
    itemRepository.save(new Item("the one ring"));

    SecurityContextHolder.clearContext();
}

From source file:com.mothsoft.alexis.security.CurrentUserUtil.java

public static void clearAuthentication() {
    SecurityContextHolder.clearContext();
}

From source file:org.web4thejob.security.SpringSecurityContext.java

@Override
public void clearContext() {
    SecurityContextHolder.clearContext();
}

From source file:ch.silviowangler.dox.DocumentServiceImplTest.java

@After
public void tearDown() throws Exception {
    SecurityContextHolder.clearContext();
}

From source file:authentication.PreAuthenticatedUserFilter.java

/** {@inheritDoc} */
@Override//ww  w .  jav a2s. co m
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) request;
    try {
        super.doFilter(request, response, chain);
    } finally {
        SecurityContextHolder.clearContext();
        final HttpSession session = req.getSession(false);
        if (session != null) {
            session.removeAttribute("SPRING_SECURITY_CONTEXT");
        }
    }
}

From source file:be.dnsbelgium.rate.spring.security.LeakyBucketVoterTest.java

@After
public void tearDown() {
    SecurityContextHolder.clearContext();
}

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

@After
public void clearContext() {
    SecurityContextHolder.clearContext();
}

From source file:ch.silviowangler.dox.AbstractIntegrationTest.java

protected void loginAs(String username) {
    SecurityContextHolder.clearContext();
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(
            new User(username, "velo", new ArrayList<GrantedAuthority>()), "velo"));
}

From source file:org.opentides.util.SecurityUtilTest.java

@Test
public void testGetSessionUserNullContext() {
    SecurityContextHolder.clearContext();
    assertNull(SecurityUtil.getSessionUser());
}

From source file:org.callistasoftware.netcare.web.controller.SecurityController.java

@RequestMapping(value = "/logout")
public String logout(final HttpSession sc, final HttpServletRequest request) {
    getLog().info("Logout");
    SecurityContextHolder.clearContext();

    if (WebUtil.isProfileActive(sc.getServletContext(), "qa")
            || WebUtil.isProfileActive(sc.getServletContext(), "prod")) {
        request.getSession(false).invalidate();
        return "redirect:/netcare/security/loggedout";
    } else {//from   w w  w  .ja va 2  s  .  c  om
        request.getSession(false).invalidate();
        return "redirect:/netcare/security/login";
    }
}