Examples of TestingAuthenticationToken


Examples of org.acegisecurity.providers.TestingAuthenticationToken

   *
   * @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpBeforeTransaction()
   */
  protected void onSetUpBeforeTransaction() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(
        new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[] {}));

  }
View Full Code Here

Examples of org.acegisecurity.providers.TestingAuthenticationToken

    public void testParser39InRoleRule() {

        SecurityContext context = new SecurityContextImpl();
        GrantedAuthority[] roles = new GrantedAuthority[] { new GrantedAuthorityImpl("ADMIN_ROLE"),
                new GrantedAuthorityImpl("USER_ROLE") };
        context.setAuthentication(new TestingAuthenticationToken("username", "username", roles));
        SecurityContextHolder.setContext(context);

        String text = "{firstName: inRole('USER_ROLE') == true : 'Current user must be in USER_ROLE'}";
        assertTrue(validate(new Person(30, "Steven"), text));
    }
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

        for (Entitlement entitlement : entitlementDAO.findAll()) {
            authorities.add(new SimpleGrantedAuthority(entitlement.getName()));
        }

        UserDetails userDetails = new User(adminUser, "FAKE_PASSWORD", true, true, true, true, authorities);
        Authentication authentication = new TestingAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities);
        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

    @Test
    public void testGetAuthenticatedUser() throws Exception {
        List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
        grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        UserDetails userDetails = new UserImpl("1", "canonical");
        Authentication authentication = new TestingAuthenticationToken(userDetails, "canonical", grantedAuthorities);
        SecurityContextHolder.getContext().setAuthentication(authentication);

        User returnedUser = userService.getAuthenticatedUser();
        assertEquals(returnedUser, userDetails);
    }
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

        TestableResponse resp = tester.renderPageAndReturnResponse("SecuredMethod");
        EasyMock.verify(MockFactory.getInstance().getMockedObjects());
        assertEquals(500,resp.getStatus()); //err not allowed!

        // login..! (wrong role)
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user1","user1","ROLE_DENIED"));
       
        EasyMock.reset(MockFactory.getInstance().getMockedObjects());
        EasyMock.replay(MockFactory.getInstance().getMockedObjects());
       
       
        try {
          tester.renderPage("securedmethod");
          fail("Should not render a document");
        } catch (Exception e) {
         
        }
        EasyMock.verify(MockFactory.getInstance().getMockedObjects());
        // status = 200 , output = '', coz of redirect to login page
       
        assertEquals(200,resp.getStatus()); //err not allowed!
       
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user1","user1","ROLE_LOGGEDIN"));
       
        EasyMock.reset(MockFactory.getInstance().getMockedObjects());
        EasyMock.replay(MockFactory.getInstance().getMockedObjects());
       
        assertTrue(tester.renderPage("securedmethod").toString().contains("Welcome back user !"));
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

    private UserDetails createPrincipal(List<GrantedAuthority> authorities ) {
        return new User(USERNAME, PASSWORD, authorities);
    }

    private Authentication createAuthentication(UserDetails principal, List<GrantedAuthority> authorities) {
        return new TestingAuthenticationToken(principal, USERNAME, authorities);
    }
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

    @Test
    public void onLogoutSuccess() throws IOException, ServletException {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        Authentication authentication = new TestingAuthenticationToken(null, null);

        logoutSuccessHandler.onLogoutSuccess(request, response, authentication);

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

Examples of org.springframework.security.authentication.TestingAuthenticationToken

    @Test
    public void onAuthenticationSuccess() throws ServletException, IOException {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        Authentication authentication = new TestingAuthenticationToken(null, null);

        successHandler.onAuthenticationSuccess(request, response, authentication);

        assertEquals(MockHttpServletResponse.SC_OK, response.getStatus());
    }
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

            .andExpect(authenticated().withAuthenticationPrincipal(user));
    }

    @Test
    public void requestProtectedUrlWithAuthentication() throws Exception {
        Authentication authentication = new TestingAuthenticationToken("test", "notused", "ROLE_USER");
        mvc
            .perform(get("/").with(authentication(authentication)))
            // Ensure we got past Security
            .andExpect(status().isNotFound())
            // Ensure it appears we are authenticated with user
View Full Code Here

Examples of org.springframework.security.authentication.TestingAuthenticationToken

        cap.setStatelessTicketCache(new MockStatelessTicketCache());
        cap.setTicketValidator(new MockTicketValidator(true));
        cap.setServiceProperties(makeServiceProperties());
        cap.afterPropertiesSet();

        TestingAuthenticationToken token = new TestingAuthenticationToken("user", "password", "ROLE_A");
        assertFalse(cap.supports(TestingAuthenticationToken.class));

        // Try it anyway
        assertEquals(null, cap.authenticate(token));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.