use of org.finra.herd.model.dto.SecurityUserWrapper in project herd by FINRAOS.
the class NamespaceSecurityAdviceTest method checkPermissionAssertNoErrorWhenUserHasMultiplePermissions.
@Test
public void checkPermissionAssertNoErrorWhenUserHasMultiplePermissions() throws Exception {
// Mock a join point of the method call
// mockMethod("foo");
JoinPoint joinPoint = mock(JoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class);
when(methodSignature.getMethod()).thenReturn(method);
when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" });
when(joinPoint.getSignature()).thenReturn(methodSignature);
when(joinPoint.getArgs()).thenReturn(new Object[] { "foo" });
String userId = "userId";
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(userId);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("foo", Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)));
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
try {
namespaceSecurityAdvice.checkPermission(joinPoint);
} catch (AccessDeniedException e) {
fail();
}
}
use of org.finra.herd.model.dto.SecurityUserWrapper in project herd by FINRAOS.
the class NamespaceSecurityAdviceTest method checkPermissionAssertNoExceptionWhenNull.
/**
* Assert no access denied exception when parameter value is null.
*/
@Test
public void checkPermissionAssertNoExceptionWhenNull() throws Exception {
// Mock a join point of the method call
// mockMethod(null);
JoinPoint joinPoint = mock(JoinPoint.class);
MethodSignature methodSignature = mock(MethodSignature.class);
Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", String.class);
when(methodSignature.getParameterNames()).thenReturn(new String[] { "namespace" });
when(methodSignature.getMethod()).thenReturn(method);
when(joinPoint.getSignature()).thenReturn(methodSignature);
when(joinPoint.getArgs()).thenReturn(new Object[] { null });
String userId = "userId";
ApplicationUser applicationUser = new ApplicationUser(getClass());
applicationUser.setUserId(userId);
applicationUser.setNamespaceAuthorizations(new HashSet<>());
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
try {
namespaceSecurityAdvice.checkPermission(joinPoint);
} catch (AccessDeniedException e) {
fail();
}
}
use of org.finra.herd.model.dto.SecurityUserWrapper in project herd by FINRAOS.
the class HerdUserDetailsService method loadUserDetails.
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
ApplicationUser user = (ApplicationUser) token.getPrincipal();
Set<GrantedAuthority> authorities = new HashSet<>();
// Add all functional points per given collection of user roles.
authorities.addAll(securityHelper.mapRolesToFunctions(user.getRoles()));
// Add all function points that are not mapped to any roles in the system.
authorities.addAll(securityHelper.getUnrestrictedFunctions());
SecurityUserWrapper result = new SecurityUserWrapper(user.getUserId(), "N/A", true, true, true, true, authorities, user);
LOGGER.debug("Loaded User: " + result);
return result;
}
use of org.finra.herd.model.dto.SecurityUserWrapper in project herd by FINRAOS.
the class HttpHeaderAuthenticationFilter method getExistingUser.
/**
* Gets the existing user.
*
* @return the existing user or null if no existing user is present.
*/
protected ApplicationUser getExistingUser() {
ApplicationUser applicationUser = null;
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
SecurityUserWrapper securityUserWrapper = (SecurityUserWrapper) authentication.getPrincipal();
if (securityUserWrapper != null) {
applicationUser = securityUserWrapper.getApplicationUser();
LOGGER.trace("Existing Application User: " + applicationUser);
return applicationUser;
}
}
return applicationUser;
}
use of org.finra.herd.model.dto.SecurityUserWrapper in project herd by FINRAOS.
the class AbstractAppTest method validateTrustedApplicationUser.
protected void validateTrustedApplicationUser() throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
assertNotNull(authentication);
SecurityUserWrapper user = (SecurityUserWrapper) authentication.getPrincipal();
ApplicationUser applicationUser = user.getApplicationUser();
assertEquals(TrustedApplicationUserBuilder.TRUSTED_USER_ID, applicationUser.getUserId());
assertEquals(TrustedApplicationUserBuilder.TRUSTED_USER_FIRST_NAME, applicationUser.getFirstName());
assertEquals(TrustedApplicationUserBuilder.TRUSTED_USER_LAST_NAME, applicationUser.getLastName());
assertEquals(TrustedApplicationUserBuilder.TRUSTED_USER_EMAIL, applicationUser.getEmail());
Set<String> roles = applicationUser.getRoles();
assertTrue(roles.contains(TrustedApplicationUserBuilder.TRUSTED_USER_ROLE));
assertNotNull(applicationUser.getSessionId());
assertEquals(TrustedApplicationUserBuilder.class, applicationUser.getGeneratedByClass());
}
Aggregations