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:org.springframework.security.web.authentication.www.DigestAuthenticationFilterTests.java

@Test
public void authenticationCreatesEmptyContext() throws Exception {
    SecurityContext existingContext = SecurityContextHolder.createEmptyContext();
    TestingAuthenticationToken existingAuthentication = new TestingAuthenticationToken("existingauthenitcated",
            "pass", "ROLE_USER");
    existingContext.setAuthentication(existingAuthentication);

    SecurityContextHolder.setContext(existingContext);

    String responseDigest = DigestAuthUtils.generateDigest(false, USERNAME, REALM, PASSWORD, "GET", REQUEST_URI,
            QOP, NONCE, NC, CNONCE);/*  w  w w  . j  av  a2s. co m*/

    request.addHeader("Authorization",
            createAuthorizationHeader(USERNAME, REALM, NONCE, REQUEST_URI, responseDigest, QOP, NC, CNONCE));

    filter.setCreateAuthenticatedToken(true);
    executeFilterInContainerSimulator(filter, request, true);

    assertThat(existingAuthentication).isSameAs(existingContext.getAuthentication());
}