use of org.finra.herd.model.dto.ApplicationUser 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.ApplicationUser 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.ApplicationUser 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.ApplicationUser in project herd by FINRAOS.
the class TrustedApplicationUserBuilder method buildUser.
/**
* Builds the application user.
*
* @param request the HTTP servlet request.
* @param includeRoles If true, the user's roles will be included. Otherwise, not.
*
* @return the application user.
*/
protected ApplicationUser buildUser(HttpServletRequest request, boolean includeRoles) {
ApplicationUser applicationUser = new ApplicationUser(this.getClass());
applicationUser.setUserId(TRUSTED_USER_ID);
applicationUser.setFirstName(TRUSTED_USER_FIRST_NAME);
applicationUser.setLastName(TRUSTED_USER_LAST_NAME);
applicationUser.setEmail(TRUSTED_USER_EMAIL);
applicationUser.setSessionId(request.getSession().getId());
applicationUser.setNamespaceAuthorizations(userNamespaceAuthorizationHelper.getAllNamespaceAuthorizations());
if (includeRoles) {
Set<String> roles = new HashSet<>();
roles.add(TRUSTED_USER_ROLE);
applicationUser.setRoles(roles);
}
return applicationUser;
}
use of org.finra.herd.model.dto.ApplicationUser 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