Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.BadCredentialsException


    super.afterPropertiesSet();
    setAuthenticationFailureHandler(new AuthenticationFailureHandler() {
      public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
          AuthenticationException exception) throws IOException, ServletException {
        if (exception instanceof BadCredentialsException) {
          exception = new BadCredentialsException(exception.getMessage(), new BadClientCredentialsException());
        }
        authenticationEntryPoint.commence(request, response, exception);
      }
    });
    setAuthenticationSuccessHandler(new AuthenticationSuccessHandler() {
View Full Code Here


    if (authentication != null && authentication.isAuthenticated()) {
      return authentication;
    }

    if (clientId == null) {
      throw new BadCredentialsException("No client credentials presented");
    }

    if (clientSecret == null) {
      clientSecret = "";
    }
View Full Code Here

    public Authentication doAuthentication(Authentication authentication)
        throws AuthenticationException {
        if (grantAccess) {
          return new TestingAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), authorities);
        } else {
            throw new BadCredentialsException(
                "MockAuthenticationManager instructed to deny access");
        }
    }
View Full Code Here

  @Test(expected = InvalidGrantException.class)
  public void testBadCredentials() {
    ResourceOwnerPasswordTokenGranter granter = new ResourceOwnerPasswordTokenGranter(new AuthenticationManager() {
      public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        throw new BadCredentialsException("test");
      }
    }, providerTokenServices, clientDetailsService, requestFactory);
    granter.grant("password", tokenRequest);
  }
View Full Code Here

  }

  @Test
  public void testCommenceWithJson() throws Exception {
    request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
    entryPoint.commence(request, response, new BadCredentialsException("Bad"));
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    assertEquals("{\"error\":\"unauthorized\",\"error_description\":\"Bad\"}", response.getContentAsString());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    assertEquals(null, response.getErrorMessage());
  }
View Full Code Here

  }

  @Test
  public void testCommenceWithOAuth2Exception() throws Exception {
    request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
    entryPoint.commence(request, response, new BadCredentialsException("Bad", new InvalidClientException(
        "Bad client")));
    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    assertEquals("{\"error\":\"invalid_client\",\"error_description\":\"Bad client\"}", response.getContentAsString());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    assertEquals(null, response.getErrorMessage());
View Full Code Here

  }

  @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());
View Full Code Here

  }

  @Test
  public void testTypeName() throws Exception {
    entryPoint.setTypeName("Foo");
    entryPoint.commence(request, response, new BadCredentialsException("Bad"));
    assertEquals("Foo realm=\"foo\", error=\"unauthorized\", error_description=\"Bad\"",
        response.getHeader("WWW-Authenticate"));
  }
View Full Code Here

        response.getHeader("WWW-Authenticate"));
  }

  @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());
  }
View Full Code Here

  }

  @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());
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.BadCredentialsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.