Search in sources :

Example 1 with SimplePrincipal

use of org.jasig.cas.client.authentication.SimplePrincipal in project uhgroupings by uhawaii-system-its-ti-iam.

the class AuthorizationServiceTest method fetchPrivilegesTest.

@Test
@WithMockUhUser
public void fetchPrivilegesTest() {
    // Setup for the mocking.
    User user = userContextService.getCurrentUser();
    String uhUuid = user.getUhUuid();
    Principal principal = new SimplePrincipal(uhUuid);
    given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    // What we are testing.
    RoleHolder roleHolder = authorizationService.fetchRoles(uhUuid, "test");
    // Check results.
    assertThat(roleHolder.size(), equalTo(4));
    assertTrue(roleHolder.contains(Role.ANONYMOUS));
    assertTrue(roleHolder.contains(Role.UH));
    assertTrue(roleHolder.contains(Role.OWNER));
    assertTrue(roleHolder.contains(Role.ADMIN));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) Principal(java.security.Principal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 2 with SimplePrincipal

use of org.jasig.cas.client.authentication.SimplePrincipal in project uhgroupings by uhawaii-system-its-ti-iam.

the class AuthorizationServiceTest method fetchDefaultTest.

@Test
@WithMockUhUser
public void fetchDefaultTest() {
    // Setup for the mocking.
    User user = userContextService.getCurrentUser();
    String uhUuid = user.getUhUuid();
    Principal principal = new SimplePrincipal(uhUuid);
    given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>(null, HttpStatus.OK));
    given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>(null, HttpStatus.OK));
    // What we are testing.
    RoleHolder roleHolder = authorizationService.fetchRoles(uhUuid, "test");
    // Check results.
    assertThat(roleHolder.size(), equalTo(2));
    assertTrue(roleHolder.contains(Role.ANONYMOUS));
    assertTrue(roleHolder.contains(Role.UH));
    assertFalse(roleHolder.contains(Role.EMPLOYEE));
    assertFalse(roleHolder.contains(Role.ADMIN));
    assertFalse(roleHolder.contains(Role.OWNER));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) Principal(java.security.Principal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 3 with SimplePrincipal

use of org.jasig.cas.client.authentication.SimplePrincipal in project uhgroupings by uhawaii-system-its-ti-iam.

the class AuthorizationServiceImpl method fetchRoles.

/**
 * Assign roles to user
 */
@Override
public RoleHolder fetchRoles(String uhUuid, String uid) {
    RoleHolder roleHolder = new RoleHolder();
    Principal principal = new SimplePrincipal(uhUuid);
    roleHolder.add(Role.ANONYMOUS);
    roleHolder.add(Role.UH);
    // Determine if user is an owner.
    if (checkResult(groupingsRestController.hasOwnerPrivs(principal))) {
        roleHolder.add(Role.OWNER);
    }
    // Determine if a user is an admin.
    if (checkResult(groupingsRestController.hasAdminPrivs(principal))) {
        roleHolder.add(Role.ADMIN);
    }
    logger.info("fetchRoles: username: " + uid + " " + roleHolder.getAuthorities() + ";");
    return roleHolder;
}
Also used : Principal(java.security.Principal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal)

Example 4 with SimplePrincipal

use of org.jasig.cas.client.authentication.SimplePrincipal in project uhgroupings by uhawaii-system-its-ti-iam.

the class UserBuilderTest method testAdminUser.

@Test
@WithMockUhUser
public void testAdminUser() {
    Map<String, String> map = new HashMap<>();
    Principal principal = new SimplePrincipal(userContextService.getCurrentUhUuid());
    map.put("uid", userContextService.getCurrentUser().getUid());
    map.put("uhUuid", userContextService.getCurrentUhUuid());
    given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
    User user = userBuilder.make(map);
    // Check results.
    assertEquals(4, user.getAuthorities().size());
    assertTrue(user.hasRole(Role.ANONYMOUS));
    assertTrue(user.hasRole(Role.UH));
    assertTrue(user.hasRole(Role.ADMIN));
    assertTrue(user.hasRole(Role.OWNER));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) HashMap(java.util.HashMap) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Principal(java.security.Principal) SimplePrincipal(org.jasig.cas.client.authentication.SimplePrincipal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Aggregations

Principal (java.security.Principal)4 SimplePrincipal (org.jasig.cas.client.authentication.SimplePrincipal)4 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 HashMap (java.util.HashMap)1