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));
}
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));
}
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;
}
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));
}
Aggregations