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:de.thm.arsnova.services.SessionServiceTest.java

@After
public void cleanup() {
    databaseDao.cleanupTestData();
    SecurityContextHolder.clearContext();
    userService.setUserAuthenticated(false);
}

From source file:org.keycloak.adapters.springsecurity.client.KeycloakClientRequestFactoryTest.java

@Test(expected = IllegalStateException.class)
public void testGetKeycloakSecurityContextNullAuthentication() throws Exception {
    SecurityContextHolder.clearContext();
    factory.getKeycloakSecurityContext();
}

From source file:business.UploadTests.java

@Test(groups = "request")
public void createRequest() {
    UserAuthenticationToken requester = getRequester();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(requester);

    RequestRepresentation representation = new RequestRepresentation();
    representation.setTitle("Test request");
    representation = requestController.start(requester, representation);
    log.info("Started request " + representation.getProcessInstanceId());
    log.info("Status: " + representation.getStatus());
    log.info("Assignee: " + representation.getAssignee());
    assertEquals(RequestStatus.OPEN, representation.getStatus());
    processInstanceId = representation.getProcessInstanceId();

    SecurityContextHolder.clearContext();
}

From source file:org.vaadin.spring.security.shared.PushSecurityInterceptor.java

@Override
public void postInspect(AtmosphereResource r) {
    LOGGER.trace("Clearing security context");
    SecurityContextHolder.clearContext();
}

From source file:business.ProcessControllerTests.java

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

From source file:com.mycompany.login.filter.AutenticacaoFilter.java

@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException failed) throws IOException, ServletException {
    //super.unsuccessfulAuthentication(request, response, failed);
    SecurityContextHolder.clearContext();
    request.removeAttribute("usuarioLogado");
    request.getSession().setAttribute("msg", mensagem);
    request.getSession().invalidate();//w ww  .  j  a  v  a2  s.  c om
    response.sendRedirect("index.xhtml");

}

From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepositoryTest.java

@After
public void clearTables() throws IOException {
    SecurityContextHolder.clearContext();
    clearAllTables(getTables());
}

From source file:com.linuxbox.enkive.message.search.AsynchronousSearchThread.java

@Override
public SearchResult call() {

    SearchResult searchResult = null;
    try {/*  w w  w.  ja  va  2 s.co m*/
        SecurityContext ctx = new SecurityContextImpl();
        ctx.setAuthentication(searchingUserAuth);
        SecurityContextHolder.setContext(ctx);
        searchResult = searchResultBuilder.getSearchResult(searchResultId);
        try {
            markSearchResultRunning(searchResult);
            SearchResult tmpSearchResult = messageSearchService.search(fields);
            searchResult.setMessageIds(tmpSearchResult.getMessageIds());
            searchResult.setTimestamp(tmpSearchResult.getTimestamp());
            searchResult.setExecutedBy(tmpSearchResult.getExecutedBy());
            searchResult.setStatus(Status.COMPLETE);
            searchResult.saveSearchResult();

        } catch (MessageSearchException e) {
            searchResult.setStatus(Status.UNKNOWN);
            searchResult.saveSearchResult();
            LOGGER.error("Could not complete message search", e);
        }
    } catch (WorkspaceException e) {
        LOGGER.error("Could not complete message search", e);
    } finally {
        SecurityContextHolder.clearContext();
    }

    return searchResult;
}

From source file:org.openlmis.notification.ResourceServerSecurityConfiguration.java

@Override
public void configure(HttpSecurity http) throws Exception {
    http.addFilterAfter(new OncePerRequestFilter() {
        @Override/*from   w  ww  .  j ava  2 s.  c o  m*/
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                FilterChain filterChain) throws ServletException, IOException {
            // We don't want to allow access to a resource with no token so clear
            // the security context in case it is actually an OAuth2Authentication
            if (tokenExtractor.extract(request) == null) {
                SecurityContextHolder.clearContext();
            }
            filterChain.doFilter(request, response);
        }
    }, AbstractPreAuthenticatedProcessingFilter.class);
    http.csrf().disable();

    http.anonymous().and().authorizeRequests()
            .antMatchers("/notification", "/webjars/**", "/notification/webjars/**", "/notification/docs/**")
            .permitAll().antMatchers("/**").fullyAuthenticated();
}

From source file:io.dacopancm.jfee.managedController.LoginBean.java

public String logout() {
    SecurityContextHolder.clearContext();
    //org.springframework.faces.security.FaceletsAuthorizeTagUtils.areNotGranted(userName)             
    return "loggedout";
}