Skip to content

Commit

Permalink
add groups added
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Nov 2, 2017
1 parent 1c928dd commit 5925619
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -69,8 +69,9 @@ public View getView(String viewId) throws Exception {
} else {
log.warn("User '" + email + "' does not exist yet, hence create account and login user ...");

user = getRealm().getIdentityManager().getUserManager().createUser(userInfo.getId(), "TODO:name", email, null);
user = getRealm().getIdentityManager().getUserManager().createUser(userInfo.getId(), "TODO:gmail", email, null);
getRealm().getIdentityManager().getUserManager().createAlias(email, user.getID());
addUserToGroups(user);
}
YanelServlet.setIdentity(new Identity(user, email), getEnvironment().getRequest().getSession(true), realm);

Expand All @@ -84,6 +85,32 @@ public View getView(String viewId) throws Exception {
return view;
}

/**
* Add registered user to particular groups by default
* @param user User to be added to groups
*/
private void addUserToGroups(User user) throws Exception {
// TODO: See src/resources/registration/src/java/org/wyona/yanel/resources/registration/UserRegistrationResource.java#addUserToGroups(User)
String groupsCSV = getResourceConfigProperty("groups");
if (groupsCSV != null) {
String[] groupIDs = null;
if (groupsCSV.indexOf(",") >= 0) {
groupIDs = groupsCSV.split(",");
} else {
groupIDs = new String[1];
groupIDs[0] = groupsCSV;
}
for (int i = 0; i < groupIDs.length; i++) {
if (getRealm().getIdentityManager().getGroupManager().existsGroup(groupIDs[i])) {
log.debug("Add user '" + user.getEmail() + "' to group: " + groupIDs[i]);
getRealm().getIdentityManager().getGroupManager().getGroup(groupIDs[i]).addMember(user);
} else {
log.warn("No such group: " + groupIDs[i]);
}
}
}
}

/**
* @return URL of token endpoint
*/
Expand Down

0 comments on commit 5925619

Please sign in to comment.