Search in sources :

Example 1 with User

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) User(edu.hawaii.its.groupings.access.User) HashMap(java.util.HashMap) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UhAttributes(edu.hawaii.its.groupings.access.UhAttributes) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UhCasAttributes(edu.hawaii.its.groupings.access.UhCasAttributes) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 2 with User

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";
}
Also used : User(edu.hawaii.its.groupings.access.User) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 3 with User

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);
}
Also used : User(edu.hawaii.its.groupings.access.User) GroupingsHTTPException(edu.hawaii.its.api.type.GroupingsHTTPException)

Example 4 with User

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) User(edu.hawaii.its.groupings.access.User) HashMap(java.util.HashMap) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UhAttributes(edu.hawaii.its.groupings.access.UhAttributes) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UhCasAttributes(edu.hawaii.its.groupings.access.UhCasAttributes) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Aggregations

User (edu.hawaii.its.groupings.access.User)4 UhAttributes (edu.hawaii.its.groupings.access.UhAttributes)2 UhCasAttributes (edu.hawaii.its.groupings.access.UhCasAttributes)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1