use of edu.hawaii.its.groupings.access.User in project uhgroupings by uhawaii-system-its-ti-iam.
the class WithMockUserSecurityContextFactory method createSecurityContext.
@Override
public SecurityContext createSecurityContext(WithMockUhUser uhUser) {
Set<GrantedAuthority> authorities = new LinkedHashSet<>();
for (String role : uhUser.roles()) {
authorities.add(new SimpleGrantedAuthority(role));
}
User user = new User(uhUser.username(), uhUser.uhUuid(), authorities);
Map<String, String> attrsMap = new HashMap<>();
attrsMap.put("cn", uhUser.name());
UhAttributes attributes = new UhCasAttributes(attrsMap);
user.setAttributes(attributes);
final Authentication auth = new UsernamePasswordAuthenticationToken(user, "pw", user.getAuthorities());
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(auth);
return context;
}
use of edu.hawaii.its.groupings.access.User in project uhgroupings by uhawaii-system-its-ti-iam.
the class ErrorControllerAdvice method handleTypeMismatchException.
// todo this is for the HolidayRestControllerTest test (should we really have this behavior?)
@ExceptionHandler(TypeMismatchException.class)
public String handleTypeMismatchException(Exception ex) {
String username = null;
User user = userContextService.getCurrentUser();
if (user != null) {
username = user.getUsername();
}
logger.error("username: " + username + "; Exception: ", ex);
emailService.sendWithStack(ex, "TypeMismatchException");
return "redirect:/error";
}
use of edu.hawaii.its.groupings.access.User in project uhgroupings by uhawaii-system-its-ti-iam.
the class ErrorControllerAdvice method exceptionResponse.
private ResponseEntity<GroupingsHTTPException> exceptionResponse(String message, Throwable cause, int status) {
String username = null;
User user = userContextService.getCurrentUser();
if (user != null) {
username = user.getUsername();
}
GroupingsHTTPException httpException = new GroupingsHTTPException(message, cause, status);
logger.error("username: " + username + "; Exception: ", httpException.getCause());
return ResponseEntity.status(status).body(httpException);
}
use of edu.hawaii.its.groupings.access.User in project uhgroupings by uhawaii-system-its-ti-iam.
the class WithMockAdminSecurityContextFactory method createSecurityContext.
@Override
public SecurityContext createSecurityContext(WithMockUhAdmin uhUser) {
Set<GrantedAuthority> authorities = new LinkedHashSet<>();
for (String role : uhUser.roles()) {
authorities.add(new SimpleGrantedAuthority(role));
}
User user = new User(uhUser.username(), uhUser.uhuuid(), authorities);
Map<String, String> attrsMap = new HashMap<>();
attrsMap.put("cn", uhUser.name());
UhAttributes attributes = new UhCasAttributes(attrsMap);
user.setAttributes(attributes);
final Authentication auth = new UsernamePasswordAuthenticationToken(user, "pw", user.getAuthorities());
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(auth);
return context;
}
Aggregations