use of org.springframework.security.authentication.BadCredentialsException in project spring-security by spring-projects.
the class OpenIDAuthenticationProviderTests method testAuthenticateFailure.
/*
* Test method for
* 'org.springframework.security.authentication.openid.OpenIDAuthenticationProvider.
* authenticate(Authentication)'
*/
@Test
public void testAuthenticateFailure() {
OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider();
provider.setAuthenticationUserDetailsService(new UserDetailsByNameServiceWrapper<OpenIDAuthenticationToken>(new MockUserDetailsService()));
Authentication preAuth = new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE, USERNAME, "", null);
assertThat(preAuth.isAuthenticated()).isFalse();
try {
provider.authenticate(preAuth);
fail("Should throw an AuthenticationException");
} catch (BadCredentialsException expected) {
assertThat("Log in failed - identity could not be verified").isEqualTo(expected.getMessage());
}
}
use of org.springframework.security.authentication.BadCredentialsException in project spring-security-oauth by spring-projects.
the class OAuth2AuthenticationEntryPointTests method testCommenceWithHtmlAndJsonAccept.
@Test
public void testCommenceWithHtmlAndJsonAccept() throws Exception {
request.addHeader("Accept", String.format("%s,%s", MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON));
entryPoint.commence(request, response, new BadCredentialsException("Bad"));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertEquals(null, response.getErrorMessage());
}
use of org.springframework.security.authentication.BadCredentialsException in project spring-security-oauth by spring-projects.
the class OAuth2AuthenticationEntryPointTests method testCommenceWithEmptyAccept.
@Test
public void testCommenceWithEmptyAccept() throws Exception {
entryPoint.commence(request, response, new BadCredentialsException("Bad"));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertEquals("{\"error\":\"unauthorized\",\"error_description\":\"Bad\"}", response.getContentAsString());
assertTrue(MediaType.APPLICATION_JSON.isCompatibleWith(MediaType.valueOf(response.getContentType())));
assertEquals(null, response.getErrorMessage());
}
use of org.springframework.security.authentication.BadCredentialsException in project spring-security-oauth by spring-projects.
the class OAuth2AuthenticationEntryPointTests method testCommenceWithHtmlAccept.
@Test
public void testCommenceWithHtmlAccept() throws Exception {
request.addHeader("Accept", MediaType.TEXT_HTML_VALUE);
entryPoint.commence(request, response, new BadCredentialsException("Bad"));
// TODO: maybe use forward / redirect for HTML content?
assertEquals(HttpServletResponse.SC_NOT_ACCEPTABLE, response.getStatus());
assertEquals("", response.getContentAsString());
assertEquals(null, response.getErrorMessage());
}
use of org.springframework.security.authentication.BadCredentialsException in project spring-security-oauth by spring-projects.
the class OAuth2AuthenticationEntryPointTests method testCommenceWithXml.
@Test
public void testCommenceWithXml() throws Exception {
request.addHeader("Accept", MediaType.APPLICATION_XML_VALUE);
entryPoint.commence(request, response, new BadCredentialsException("Bad"));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
assertEquals("<oauth><error_description>Bad</error_description><error>unauthorized</error></oauth>", response.getContentAsString());
assertEquals(MediaType.APPLICATION_XML_VALUE, response.getContentType());
assertEquals(null, response.getErrorMessage());
}
Aggregations