use of org.springframework.security.authentication.jaas.JaasGrantedAuthority in project kylo by Teradata.
the class AboutKyloController method getCurrentUser.
/**
* Gets information about the current user.
*/
@GET
@Path("/me")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets information about the current user.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the user.", response = User.class))
public Response getCurrentUser() {
// Create principal from current user
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = new User();
user.setEnabled(true);
if (auth.getPrincipal() instanceof UserDetails) {
final UserDetails details = (UserDetails) auth.getPrincipal();
user.setGroups(details.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet()));
user.setSystemName(details.getUsername());
} else {
user.setGroups(auth.getAuthorities().stream().filter(JaasGrantedAuthority.class::isInstance).map(JaasGrantedAuthority.class::cast).filter(authority -> authority.getPrincipal() instanceof Group).map(JaasGrantedAuthority::getAuthority).collect(Collectors.toSet()));
user.setSystemName(auth.getName());
}
// Return principal
return Response.ok(user).build();
}
use of org.springframework.security.authentication.jaas.JaasGrantedAuthority in project kylo by Teradata.
the class SecurityContextUtil method getCurrentPrincipals.
public static Set<Principal> getCurrentPrincipals() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Set<Principal> principals = new HashSet<>();
if (auth != null) {
for (GrantedAuthority grant : auth.getAuthorities()) {
if (grant instanceof JaasGrantedAuthority) {
JaasGrantedAuthority jaasGrant = (JaasGrantedAuthority) grant;
principals.add(jaasGrant.getPrincipal());
} else {
String authority = grant.getAuthority();
if (authority != null) {
principals.add(new SimplePrincipal(authority));
}
}
}
principals.add(new UsernamePrincipal(auth.getName()));
} else {
principals.add(new AnonymousPrincipal());
}
return principals;
}
use of org.springframework.security.authentication.jaas.JaasGrantedAuthority in project kylo by Teradata.
the class DefaultKyloJaasAuthenticationProvider method createSubject.
private Subject createSubject(Authentication auth) {
Set<Principal> principals = auth.getAuthorities().stream().filter(grant -> grant instanceof JaasGrantedAuthority).map(JaasGrantedAuthority.class::cast).map(jga -> jga.getPrincipal()).collect(Collectors.toCollection(HashSet::new));
principals.add(new UsernamePrincipal(auth.getName()));
Subject subject = Subject.getSubject(AccessController.getContext());
if (subject == null) {
return new Subject(false, principals, new HashSet<>(), new HashSet<>());
} else {
subject.getPrincipals().addAll(principals);
return subject;
}
}
Aggregations