Java 类org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException 实例源码

项目:Your-Microservice    文件:YourMicroserviceUserDetailsService.java   
@Override
public UserDetails loadUserByUsername(String uName) throws UsernameNotFoundException {
    YourEntity yourEntity =  null;
    if (uName == null || uName.isEmpty()) {
        throw new PreAuthenticatedCredentialsNotFoundException("No User Email Address Supplied for Obtaining User, Ignoring!");
    }
        LOGGER.info("Authenticating:[{}]", uName);
        yourEntity = identityProviderEntityManager.findYourEntityByEmail(uName);
        if (yourEntity == null) {
            LOGGER.warn("YourEntity Object Not Found based Upon Email:[{}]",uName);
            throw new UsernameNotFoundException("No User with email address '" + uName + "' could be found.");
        }
    LOGGER.info("YourEntity Object Found based Upon Email:[{}]",uName);
    return new YourMicroserviceUserDetails(yourEntity);
}
项目:Your-Microservice    文件:AuthenticationController.java   
@ExceptionHandler({org.springframework.http.converter.HttpMessageNotReadableException.class,
        PreAuthenticatedCredentialsNotFoundException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)  // 400
@ResponseBody
public String resolveBadRequestExceptions() {
    return "error";
}
项目:ARCLib    文件:PreauthFilter.java   
protected String extractUsername(HttpServletRequest request) {
    try {
        return (String)getPreAuthenticatedPrincipal(request);
    } catch (PreAuthenticatedCredentialsNotFoundException ex) {
        return null;
    }
}
项目:iBeaconServer    文件:UserUrlFilter.java   
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    String requestURI = request.getRequestURI();
    if (requestURI.startsWith("/human/") && !requestURI.startsWith("/human/register")) {
        String authUsername = getAuthUsername(request);
        String uriUsername = getUriUsername(requestURI);
        if (!authUsername.equals(uriUsername)) {
            throw new PreAuthenticatedCredentialsNotFoundException("Unauthorized access.");
        }
    }
    filterChain.doFilter(request, response);
}
项目:iBeaconServer    文件:UserUrlFilter.java   
private String getAuthUsername(HttpServletRequest request) {
    String authorizationString = request.getHeader("Authorization");
    if (authorizationString == null) {
        throw new PreAuthenticatedCredentialsNotFoundException("Unauthorized access. Please provide preemptive HTTP Basic authorization credentials with every request.");
    }
    authorizationString = authorizationString.substring("Basic".length()).trim();
    String credentials = new String(Base64.decode(authorizationString.getBytes()), Charset.forName("UTF-8"));
    return (credentials.split(":", 2))[0];
}
项目:opennmszh    文件:RequestAttributePreAuthenticationProcessingFilter.java   
/** {@inheritDoc} */
@Override
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
    Object principal = request.getAttribute(m_principalRequestAttribute);

    if (principal == null) {
        throw new PreAuthenticatedCredentialsNotFoundException(m_principalRequestAttribute 
                + " attribute not found in request.");
    }

    return principal;
}
项目:bandwidth-on-demand    文件:BodAuthenticationEntryPointTest.java   
@Test
public void request_that_match_a_machine_path_should_receive_403() throws IOException, ServletException {
  request.setServletPath("/nsi/v2/provider");

  subject.commence(request, response, new PreAuthenticatedCredentialsNotFoundException("foo"));

  assertTrue(response.getStatus() == HttpServletResponse.SC_FORBIDDEN);
}
项目:bandwidth-on-demand    文件:BodAuthenticationEntryPointTest.java   
@Test
public void request_that_dont_match_a_machine_path_should_see_redirect_to_splashPath() throws IOException, ServletException{
  request.setServletPath("/bod");
  request.setPathInfo("/noc");

  subject.commence(request, response, new PreAuthenticatedCredentialsNotFoundException("foo"));

  assertTrue(response.getStatus() == HttpServletResponse.SC_MOVED_TEMPORARILY);
}
项目:metka    文件:ShibAuthFilter.java   
@Override
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
    MetkaAuthenticationDetails details = buildDetails(request);
    if(!StringUtils.hasText(details.getSessionId())) {
        throw new PreAuthenticatedCredentialsNotFoundException("Shibboleth session id not found.");
    }
    String userName = details.getUserName();
    if(!StringUtils.hasText(userName)) {
        throw new PreAuthenticatedCredentialsNotFoundException("No user name for shibboleth session.");
    }
    return userName;
}
项目:bootstrap    文件:ExceptionMapperResource.java   
@DELETE
@Path("security-401")
public void throwAuthenticationException() {
    throw new PreAuthenticatedCredentialsNotFoundException("message");
}
项目:bootstrap    文件:ApiTokenAuthenticationFilterTest.java   
@Test(expected = PreAuthenticatedCredentialsNotFoundException.class)
public void testPrincipalHeaderMissing() {
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    filter.setExceptionIfHeaderMissing(true);
    Assert.assertNull(filter.getPreAuthenticatedPrincipal(request));
}
项目:bootstrap    文件:AuthenticationExceptionMapperTest.java   
@Test
public void toResponse() {
    final PreAuthenticatedCredentialsNotFoundException exception = new PreAuthenticatedCredentialsNotFoundException("message-error");
    check(mock(new AuthenticationExceptionMapper()).toResponse(exception), 401,
            "{\"code\":\"security\",\"message\":\"message-error\",\"parameters\":null,\"cause\":null}");
}