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:cherry.foundation.springmvc.OperationLogHandlerInterceptorTest.java

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

From source file:org.zalando.stups.oauth2.spring.client.SecurityContextTokenProviderTest.java

@Test(expected = OAuth2Exception.class)
public void testTokenUnavailable() throws Exception {
    SecurityContextHolder.clearContext();
    tokenProvider.obtainAccessToken(mock(OAuth2ProtectedResourceDetails.class), mock(AccessTokenRequest.class));
}

From source file:org.terasoluna.tourreservation.app.reservetour.ReserveTourHelperTest.java

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

    reserveHelper = new ReserveTourHelper();
    tourInfoSharedService = mock(TourInfoSharedService.class);
    reserveService = mock(ReserveService.class);
    priceCalculateSharedSerivce = mock(PriceCalculateSharedSerivce.class);

    DozerBeanMapper dozerBeanMapper = new DozerBeanMapper();

    reserveHelper.tourInfoSharedService = tourInfoSharedService;
    reserveHelper.reserveService = reserveService;
    reserveHelper.priceCalculateService = priceCalculateSharedSerivce;
    reserveHelper.dozerBeanMapper = dozerBeanMapper;

    // setup mock behavior
    String tourCode = "xxxxx";

    tourInfo = new TourInfo();
    tourInfo.setTourCode(tourCode);//  w  w  w .ja  v  a 2  s. com
    tourInfo.setBasePrice(10000);
    Arrival a = new Arrival();
    a.setArrCode("1234");
    tourInfo.setArrival(a);

    Departure departure = new Departure();
    departure.setDepCode("5678");
    tourInfo.setDeparture(departure);

    Accommodation accommodation = new Accommodation();
    accommodation.setAccomCode("9012");
    tourInfo.setAccommodation(accommodation);

    when(tourInfoSharedService.findOneWithDetails(tourCode)).thenReturn(tourInfo);

    priceCalculateOutput = new PriceCalculateOutput();
    priceCalculateOutput.setSumPrice(100000);
    priceCalculateOutput.setAdultCount(1);
    priceCalculateOutput.setChildCount(2);
    when(priceCalculateSharedSerivce.calculatePrice(10000, 1, 2)).thenReturn(priceCalculateOutput);

    customer = new Customer("12345678");

    userDetails = new ReservationUserDetails(customer);
}

From source file:org.openengsb.opencit.core.projectmanager.internal.SchedulingServiceImpl.java

@Override
public void setupAndStartScmPoller(final Project project) {
    Thread thread = new Thread() {
        @Override//from w w  w.  j a v a2s  .  co m
        public void run() {
            SecurityContextHolder.clearContext();
            PollTask task = createPollTask(project);
            pollTasks.put(project.getId(), task);
            resumeScmPoller(project.getId());
        }
    };
    thread.start();
    try {
        thread.join();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.wicketopia.example.web.page.HomePage.java

public HomePage() {
    add(new Scaffold<Person>("scaffold", Person.class, persistenceProvider));
    add(new Link("loginAdmin") {
        @Override/* w  w  w  .  j  av  a 2 s  .  c o m*/
        public void onClick() {
            final UsernamePasswordAuthenticationToken tok = new UsernamePasswordAuthenticationToken("admin",
                    "admin");
            SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(tok));
            setResponsePage(HomePage.class);
            setRedirect(true);
        }

        @Override
        public boolean isVisible() {
            return SecurityContextHolder.getContext().getAuthentication() == null;
        }
    });

    add(new Link("logout") {
        @Override
        public void onClick() {
            SecurityContextHolder.clearContext();
            setResponsePage(HomePage.class);
            setRedirect(true);
        }

        @Override
        public boolean isVisible() {
            return SecurityContextHolder.getContext().getAuthentication() != null;
        }
    });
}

From source file:business.SmallExcerptListTests.java

@Test(groups = "request", dependsOnMethods = "approveRequest")
public void uploadExcerptList() throws IOException {
    UserAuthenticationToken palga = getPalga();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(palga);

    RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId);
    log.info("Status: " + representation.getStatus());

    log.info("Activity: " + representation.getActivityId());
    if (representation.getActivityId() == null) {
        for (Task task : taskService.createTaskQuery().list()) {
            log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: "
                    + task.getName() + ", key: " + task.getTaskDefinitionKey());
        }//w  ww.j  ava  2  s.  c  o  m
    }

    log.info("uploadExcerptList: processInstanceId = " + processInstanceId);

    representation = requestController.claim(palga, processInstanceId, representation);

    ClassLoader classLoader = getClass().getClassLoader();
    URL resource = classLoader.getResource("test/Example excerptlist.csv");
    InputStream input = resource.openStream();
    MultipartFile file = new MockMultipartFile(resource.getFile(), input);

    Integer flowTotalChunks = 1;
    Integer flowChunkNumber = 1;
    String flowIdentifier = "flow";

    int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(),
            flowTotalChunks, flowChunkNumber, flowIdentifier, file);

    assertEquals(3, entryCount);

    SecurityContextHolder.clearContext();
}

From source file:edu.umn.msi.tropix.webgui.server.security.impl.SpringAdaptingLoginHandlerImpl.java

public void logout() {
    //Code roughly resembles SpringSecurity's SecurityContextLogoutHandler class
    final HttpSession session = httpSessionSupplier.get();
    session.invalidate();/*  ww  w . j  a va  2s  . co m*/
    SecurityContextHolder.clearContext();
    LOG.debug("Cleared context and invalidated HttpSession.");
}

From source file:business.LargerExcerptListTests.java

@Test(groups = "request", dependsOnMethods = "approveRequest")
public void uploadExcerptList() throws IOException {
    UserAuthenticationToken palga = getPalga();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(palga);

    RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId);
    log.info("Status: " + representation.getStatus());

    log.info("Activity: " + representation.getActivityId());
    if (representation.getActivityId() == null) {
        for (Task task : taskService.createTaskQuery().list()) {
            log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: "
                    + task.getName() + ", key: " + task.getTaskDefinitionKey());
        }//from  ww w.  ja v  a2  s  .  c o  m
    }

    log.info("uploadExcerptList: processInstanceId = " + processInstanceId);

    representation = requestController.claim(palga, processInstanceId, representation);

    ClassLoader classLoader = getClass().getClassLoader();
    URL resource = classLoader.getResource("test/Example excerptlist 20150521 v2.csv");
    InputStream input = resource.openStream();
    MultipartFile file = new MockMultipartFile(resource.getFile(), input);

    Integer flowTotalChunks = 1;
    Integer flowChunkNumber = 1;
    String flowIdentifier = "flow";

    int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(),
            flowTotalChunks, flowChunkNumber, flowIdentifier, file);

    assertEquals(6, entryCount);

    SecurityContextHolder.clearContext();
}

From source file:org.cloudfoundry.identity.uaa.authentication.manager.LoginAuthenticationManagerTests.java

@Test
public void testNotProcessingNotAuthenticated() {
    SecurityContextHolder.clearContext();
    Authentication authentication = manager
            .authenticate(UaaAuthenticationTestFactory.getAuthenticationRequest("foo"));
    assertNull(authentication);// w w w  .j a v a2s .  c o  m
}

From source file:com.ram.topup.business.service.authentication.impl.AuthenticationServiceImpl.java

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