Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.AuthenticationCredentialsNotFoundException


            @Override
            public Object invoke(MethodInvocation invocation) throws Throwable {
                SecurityContext securityContext = SecurityContextHolder.getContext();
                Authentication authentication = securityContext.getAuthentication();
                if (authentication == null) {
                    throw new AuthenticationCredentialsNotFoundException("No authentication found in current security context");
                }
                return invocation.getMethod().invoke(authentication, invocation.getArguments());
            }
        });
    }
View Full Code Here


    @Test
    public void commence() throws IOException, ServletException {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        AuthenticationException ex = new AuthenticationCredentialsNotFoundException("");

        authenticationEntryPoint.commence(request, response, ex);

        assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    }
View Full Code Here

            throws AuthenticationCredentialsNotFoundException {
        // need to check to see if the current user has a SwitchUserGrantedAuthority
        Authentication current = SecurityContextHolder.getContext().getAuthentication();

        if (null == current) {
            throw new AuthenticationCredentialsNotFoundException(messages.getMessage(
                    "SwitchUserFilter.noCurrentUser", "No current user associated with this request"));
        }

        // check to see if the current user did actual switch to another user
        // if so, get the original source user so we can switch back
        Authentication original = getSourceAuthentication(current);

        if (original == null) {
            logger.debug("Could not find original user Authentication object!");
            throw new AuthenticationCredentialsNotFoundException(messages.getMessage(
                    "SwitchUserFilter.noOriginalAuthentication",
                    "Could not find original Authentication object"));
        }

        // get the source user details
View Full Code Here

     * @param reason        to be provided in the exception detail
     * @param secureObject  that was being called
     * @param configAttribs that were defined for the secureObject
     */
    private void credentialsNotFound(String reason, Object secureObject, Collection<ConfigAttribute> configAttribs) {
        AuthenticationCredentialsNotFoundException exception = new AuthenticationCredentialsNotFoundException(reason);

        AuthenticationCredentialsNotFoundEvent event = new AuthenticationCredentialsNotFoundEvent(secureObject,
                configAttribs, exception);
        publishEvent(event);

View Full Code Here

                return super.authenticate(response);
            }
            if(isAuthenticated()) {
                return true;
            }
            entryPoint.commence(this, response, new AuthenticationCredentialsNotFoundException("User is not Authenticated"));
            return false;
        }
View Full Code Here

    public void testCommence() {
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse resp = new MockHttpServletResponse();
        Http403ForbiddenEntryPoint fep = new Http403ForbiddenEntryPoint();
        try {
            fep.commence(req,resp,new AuthenticationCredentialsNotFoundException("test"));
            assertEquals("Incorrect status",resp.getStatus(),HttpServletResponse.SC_FORBIDDEN);
        } catch (IOException e) {
            fail("Unexpected exception thrown: "+e);
        } catch (ServletException e) {
            fail("Unexpected exception thrown: "+e);
View Full Code Here

public class AuthenticationCredentialsNotFoundEventTests {

    @Test(expected=IllegalArgumentException.class)
    public void testRejectsNulls() {
        new AuthenticationCredentialsNotFoundEvent(null, SecurityConfig.createList("TEST"),
                new AuthenticationCredentialsNotFoundException("test"));
    }
View Full Code Here

    }

    @Test(expected=IllegalArgumentException.class)
    public void testRejectsNulls2() {
        new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
                new AuthenticationCredentialsNotFoundException("test"));
    }
View Full Code Here

        // invalid user. someone has either spoofed a cookie or the user account
        // is no longer in
        // the database.
        logger.warning("No user exists for principal found in security context authentication: " + username);
        SecurityContextHolder.clearContext();
        throw new AuthenticationCredentialsNotFoundException("Invalid user credentials found - username " + username
            + " does not exist in this wiki installation");
      }
    }
    return user;
  }
View Full Code Here

   * @throws AuthenticationCredentialsNotFoundException If authentication
   *  credentials are unavailable.
   */
  public static WikiUserDetails initWikiUserDetails(Authentication auth) throws AuthenticationCredentialsNotFoundException {
    if (auth == null) {
      throw new AuthenticationCredentialsNotFoundException("No authentication credential available");
    }
    if (auth instanceof AnonymousAuthenticationToken || !(auth.getPrincipal() instanceof UserDetails)) {
      // anonymous user
      return new WikiUserDetails(ANONYMOUS_USER_USERNAME, "", true, true, true, true, auth.getAuthorities());
    }
View Full Code Here

TOP

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

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.