use of com.tremolosecurity.unison.openshiftv3.model.groups.GroupItem in project OpenUnison by TremoloSecurity.
the class OpenShiftTarget method findUser.
@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
try {
User user = null;
String token = this.getAuthToken();
// users aren't bound to groups and there's no way to directly lookup what groups a user has
// so we need to read all groups and see if the user exists
ArrayList<String> groupsForUser = new ArrayList<String>();
HttpCon con = this.createClient();
StringBuffer b = new StringBuffer();
com.tremolosecurity.unison.openshiftv3.model.List<GroupItem> groupList = null;
try {
String json = callWS(token, con, "/apis/user.openshift.io/v1/groups");
Gson gson = new Gson();
TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<GroupItem>> tokenType = new TypeToken<com.tremolosecurity.unison.openshiftv3.model.List<GroupItem>>() {
};
groupList = gson.fromJson(json, tokenType.getType());
b.append("/apis/user.openshift.io/v1/users/").append(userID);
json = callWS(token, con, b.toString());
com.tremolosecurity.unison.openshiftv3.model.users.User osUser = gson.fromJson(json, com.tremolosecurity.unison.openshiftv3.model.users.User.class);
if (osUser.getKind().equalsIgnoreCase("User")) {
user = new User(userID);
for (String attrName : osUser.getMetadata().keySet()) {
if (!attrName.equalsIgnoreCase("fullName") && attributes.contains(attrName)) {
user.getAttribs().put(attrName, new Attribute(attrName, (String) osUser.getMetadata().get(attrName)));
}
}
if (attributes.contains("fullName") && osUser.getFullName() != null) {
user.getAttribs().put("fullName", new Attribute("fullName", osUser.getFullName()));
}
}
} finally {
if (con != null) {
con.getBcm().shutdown();
}
}
for (GroupItem group : groupList.getItems()) {
if (group.getUsers() != null && group.getUsers().contains(userID)) {
groupsForUser.add((String) group.getMetadata().get("name"));
}
}
if (groupsForUser.isEmpty()) {
return user;
} else {
if (user == null) {
// user = new User(userID);
return null;
}
user.getGroups().addAll(groupsForUser);
return user;
}
} catch (Exception e) {
throw new ProvisioningException("Could not load " + userID, e);
}
}
Aggregations