use of org.dcache.restful.providers.UserAttributes in project dcache by dCache.
the class UserResource method getUserAttributes.
@GET
@ApiOperation(value = "Provide information about the current user.", notes = "An introspection endpoint to allow the client to discover " + "information about the current user.")
@Produces(MediaType.APPLICATION_JSON)
public UserAttributes getUserAttributes(@Context HttpServletRequest request) {
UserAttributes user = new UserAttributes();
Subject subject = RequestUser.getSubject();
if (Subjects.isNobody(subject)) {
user.setStatus(UserAttributes.AuthenticationStatus.ANONYMOUS);
user.setUid(null);
user.setGids(null);
user.setRoles(null);
} else {
user.setStatus(UserAttributes.AuthenticationStatus.AUTHENTICATED);
user.setUid(Subjects.getUid(subject));
user.setUsername(Subjects.getUserName(subject));
List<Long> gids = Arrays.stream(Subjects.getGids(subject)).boxed().collect(Collectors.toList());
user.setGids(gids);
List<String> emails = Subjects.getEmailAddresses(subject);
user.setEmail(emails.isEmpty() ? null : emails);
for (LoginAttribute attribute : getLoginAttributes(request)) {
if (attribute instanceof HomeDirectory) {
user.setHomeDirectory(((HomeDirectory) attribute).getHome());
} else if (attribute instanceof RootDirectory) {
user.setRootDirectory(((RootDirectory) attribute).getRoot());
} else if (attribute instanceof Role) {
if (user.getRoles() == null) {
user.setRoles(new ArrayList<>());
}
user.getRoles().add(((Role) attribute).getRole());
} else if (attribute instanceof UnassertedRole) {
if (user.getUnassertedRoles() == null) {
user.setUnassertedRoles(new ArrayList<>());
}
user.getUnassertedRoles().add(((UnassertedRole) attribute).getRole());
}
}
}
return user;
}
Aggregations