List of usage examples for org.springframework.security.core.context SecurityContextHolder clearContext
public static void clearContext()
From source file:de.thm.arsnova.services.QuestionServiceTest.java
@Before public void startup() { SecurityContextHolder.clearContext(); }
From source file:org.callistasoftware.netcare.web.mobile.controller.MobileController.java
/** * Logs out the user from the app./*from ww w .ja v a2s . c om*/ * * @return JSON */ @RequestMapping(value = "/logout") @ResponseBody public final String appLogout(final HttpSession sc, final HttpServletRequest request) { getLog().info("App Logout"); SecurityContextHolder.clearContext(); request.getSession(false).invalidate(); return "{ \"loggedout\": true }"; }
From source file:de.thm.arsnova.services.QuestionServiceTest.java
@After public void cleanup() { SecurityContextHolder.clearContext(); }
From source file:org.jasig.springframework.security.portlet.context.PortletSecurityContextPersistenceFilter.java
@Override protected void doCommonFilter(PortletRequest request, PortletResponse response, FilterChain chain) throws IOException, PortletException { if (request.getAttribute(FILTER_APPLIED) != null) { // ensure that filter is only applied once per request PortletFilterUtils.doFilter(request, response, chain); return;//from w w w. j a va2 s . com } final boolean debug = logger.isDebugEnabled(); request.setAttribute(FILTER_APPLIED, Boolean.TRUE); if (forceEagerSessionCreation) { PortletSession session = request.getPortletSession(); if (debug && session.isNew()) { logger.debug("Eagerly created session: " + session.getId()); } } PortletRequestResponseHolder holder = new PortletRequestResponseHolder(request, response); SecurityContext contextBeforeChainExecution = repo.loadContext(holder); try { SecurityContextHolder.setContext(contextBeforeChainExecution); PortletFilterUtils.doFilter(holder.getRequest(), holder.getResponse(), chain); } finally { SecurityContext contextAfterChainExecution = SecurityContextHolder.getContext(); // Crucial removal of SecurityContextHolder contents - do this before anything else. SecurityContextHolder.clearContext(); repo.saveContext(contextAfterChainExecution, holder); request.removeAttribute(FILTER_APPLIED); if (debug) { logger.debug("SecurityContextHolder now cleared, as request processing completed"); } } }
From source file:org.cloudfoundry.identity.uaa.authentication.manager.ScopeAuthenticationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {/*from w w w .j a v a 2s. c o m*/ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || (!(authentication instanceof OAuth2Authentication))) { throw new InvalidTokenException("Missing oauth token."); } authenticationManager.authenticate(authentication); chain.doFilter(request, response); } catch (AuthenticationException e) { authenticationEntryPoint.commence((HttpServletRequest) request, (HttpServletResponse) response, e); SecurityContextHolder.clearContext(); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.security.SpringAuthenticatedWebSession.java
@Override public void signOut() { super.signOut(); SecurityContextHolder.clearContext(); }
From source file:ar.com.zauber.commons.social.oauth.examples.web.controllers.WelcomeController.java
/** * Join!/*w w w . j av a 2 s. c o m*/ * * @param username * @return * @throws IOException */ @RequestMapping(method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) public ModelAndView doPost(@RequestParam(value = "username", required = true) final String username) throws IOException { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); ExampleUserDetails principal = (ExampleUserDetails) auth.getPrincipal(); ExampleUser user = new ExampleUser(); user.setUsername(username); user.setAccessToken(principal.getAccessToken()); userDao.save(user); SecurityContextHolder.clearContext(); return new ModelAndView("index"); }
From source file:net.cristcost.study.services.ServiceTestUtil.java
private static void clearAuthentication(PrintWriter writer, SecurityContext oldContext) { if (oldContext != SecurityContextHolder.getContext()) { SecurityContextHolder.clearContext(); SecurityContextHolder.setContext(oldContext); writer.println("@Restoring older context after secured session"); }//from w w w . j a va2 s . c om }
From source file:eu.freme.broker.security.ManagementEndpointAuthenticationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = asHttp(request); HttpServletResponse httpResponse = asHttp(response); Optional<String> username = Optional.fromNullable(httpRequest.getHeader("X-Auth-Username")); Optional<String> password = Optional.fromNullable(httpRequest.getHeader("X-Auth-Password")); String resourcePath = new UrlPathHelper().getPathWithinApplication(httpRequest); try {/*from w w w . jav a2s . c o m*/ if (postToManagementEndpoints(resourcePath)) { logger.debug("Trying to authenticate user {} for management endpoint by X-Auth-Username method", username); processManagementEndpointUsernamePasswordAuthentication(username, password); } logger.debug("ManagementEndpointAuthenticationFilter is passing request down the filter chain"); chain.doFilter(request, response); } catch (AuthenticationException authenticationException) { SecurityContextHolder.clearContext(); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authenticationException.getMessage()); } }
From source file:org.openinfinity.core.aspect.MultiTenantAspectIntegrationTest.java
@After public void tearDown() { SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.clearContext(); }