Search in sources :

Example 1 with UhCasAttributes

use of edu.hawaii.its.groupings.access.UhCasAttributes 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 UhCasAttributes

use of edu.hawaii.its.groupings.access.UhCasAttributes 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

UhAttributes (edu.hawaii.its.groupings.access.UhAttributes)2 UhCasAttributes (edu.hawaii.its.groupings.access.UhCasAttributes)2 User (edu.hawaii.its.groupings.access.User)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