Example usage for org.springframework.security.web.authentication.www DigestAuthUtils encodePasswordInA1Format

List of usage examples for org.springframework.security.web.authentication.www DigestAuthUtils encodePasswordInA1Format

Introduction

In this page you can find the example usage for org.springframework.security.web.authentication.www DigestAuthUtils encodePasswordInA1Format.

Prototype

static String encodePasswordInA1Format(String username, String realm, String password) 

Source Link

Usage

From source file:org.springframework.security.web.authentication.www.DigestAuthenticationFilterTests.java

@Test
public void testNormalOperationWhenPasswordIsAlreadyEncoded() throws Exception {
    String encodedPassword = DigestAuthUtils.encodePasswordInA1Format(USERNAME, REALM, PASSWORD);
    String responseDigest = DigestAuthUtils.generateDigest(true, USERNAME, REALM, encodedPassword, "GET",
            REQUEST_URI, QOP, NONCE, NC, CNONCE);

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

    executeFilterInContainerSimulator(filter, request, true);

    assertThat(SecurityContextHolder.getContext().getAuthentication()).isNotNull();
    assertThat(/*w  ww. jav  a 2  s.c  o m*/
            ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername())
                    .isEqualTo(USERNAME);
}