Package org.springframework.security.core

Examples of org.springframework.security.core.Authentication


        permissionEvaluator = new TodoPermissionEvaluator();
    }

    @Test
    public void hasPermissionWhenUserIsAnonymous() {
        Authentication anonymous = createAuthenticationForAnonymousUser();
        boolean hasPermission = permissionEvaluator.hasPermission(anonymous, DOMAIN_OBJECT_TODO, PERMISSION_ADD);
        assertFalse(hasPermission);
    }
View Full Code Here


        assertFalse(hasPermission);
    }

    @Test
    public void hasPermissionWhenUserIsLoggedInAndTargetDomainObjectIsUnknown() {
        Authentication loggedInUser = createAuthenticationForLoggedInUser(SecurityRole.ROLE_USER.name());
        boolean hasPermission = permissionEvaluator.hasPermission(loggedInUser, new Todo(), PERMISSION_ADD);
        assertFalse(hasPermission);
    }
View Full Code Here

        assertFalse(hasPermission);
    }

    @Test
    public void hasPermissionWhenUserIsLoggedInButHasUnknownRole() {
        Authentication loggedInUser = createAuthenticationForLoggedInUser(ROLE_UNKNOWN);
        boolean hasPermission = permissionEvaluator.hasPermission(loggedInUser, DOMAIN_OBJECT_TODO, PERMISSION_ADD);
        assertFalse(hasPermission);
    }
View Full Code Here

        assertFalse(hasPermission);
    }

    @Test
    public void hasPermissionWhenUserIsLoggedIn() {
        Authentication loggedInUser = createAuthenticationForLoggedInUser(SecurityRole.ROLE_USER.name());
        boolean hasPermission = permissionEvaluator.hasPermission(loggedInUser, DOMAIN_OBJECT_TODO, PERMISSION_ADD);
        assertTrue(hasPermission);
    }
View Full Code Here

        assertTrue(hasPermission);
    }

    @Test
    public void hasPermissionNotImplemented() {
        Authentication loggedInUser = createAuthenticationForLoggedInUser(SecurityRole.ROLE_USER.name());
        boolean hasPermission = permissionEvaluator.hasPermission(loggedInUser, TARGET_ID, DOMAIN_OBJECT_TODO, PERMISSION_ADD);
        assertFalse(hasPermission);
    }
View Full Code Here

    public UserDetails getPrincipal() {
        LOGGER.debug("Getting principal from the security context");

        UserDetails principal = null;

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication != null) {
            Object currentPrincipal = authentication.getPrincipal();
            if (currentPrincipal instanceof UserDetails) {
                principal = (UserDetails) currentPrincipal;
            }
        }
View Full Code Here

    }

    @Test
    public void getPrincipal() {
        SecurityContext securityContextMock = mock(SecurityContext.class);
        Authentication authenticationMock = mock(Authentication.class);

        PowerMockito.mockStatic(SecurityContextHolder.class);
        when(SecurityContextHolder.getContext()).thenReturn(securityContextMock);
        when(securityContextMock.getAuthentication()).thenReturn(authenticationMock);

        UserDetails expectedPrincipal = new User("user", "password", new ArrayList<GrantedAuthority>());
        when(authenticationMock.getPrincipal()).thenReturn(expectedPrincipal);

        UserDetails actualPrincipal = securityContextUtil.getPrincipal();

        PowerMockito.verifyStatic(times(1));
        SecurityContextHolder.getContext();
View Full Code Here

    }

    @Test
    public void getPrincipalWhenAuthenticationDoesNotImplementUserDetails() {
        SecurityContext securityContextMock = mock(SecurityContext.class);
        Authentication authenticationMock = mock(Authentication.class);

        PowerMockito.mockStatic(SecurityContextHolder.class);
        when(SecurityContextHolder.getContext()).thenReturn(securityContextMock);
        when(securityContextMock.getAuthentication()).thenReturn(authenticationMock);
        when(authenticationMock.getPrincipal()).thenReturn(new String(""));

        UserDetails principal = securityContextUtil.getPrincipal();

        PowerMockito.verifyStatic(times(1));
        SecurityContextHolder.getContext();
View Full Code Here

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

        successHandler.onAuthenticationSuccess(request, response, authentication);

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

    @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

TOP

Related Classes of org.springframework.security.core.Authentication

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.