{
String entityid = rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);
if (entityid == null || entityid.trim().length() == 0)
{
logger.error("UserGroupBrowser: Failed to get entity: " + entityid );
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, "UserGroupForm");
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_MISSING_PARAMETER);
rundata.setRedirectURI(duri.toString());
return;
}
JetspeedUser user = JetspeedSecurity.getUser(entityid);
if (null == user)
{
logger.error("UserGroupBrowser: Failed to get user: " + entityid );
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, "UserGroupForm");
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_MISSING_PARAMETER);
rundata.setRedirectURI(duri.toString());
return;
}
try
{
List groups = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_GROUPS);
List selected = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_SELECTED);
if (groups == null || selected == null)
{
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, "UserGroupForm");
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_MISSING_PARAMETER);
rundata.setRedirectURI(duri.toString());
return;
}
//
// walk thru all the roles, see if anything changed
// if changed, update the database
//
for (int ix = 0; ix < groups.size(); ix++)
{
boolean newValue = rundata.getParameters().getBoolean("box_" + ((Group)groups.get(ix)).getName(), false);
boolean oldValue = ((Boolean)selected.get(ix + 1)).booleanValue();
if (newValue != oldValue)
{
if (newValue == true)
{
// grant a role to a user
JetspeedSecurity.joinGroup( user.getUserName(),
((Group)groups.get(ix)).getName() );
}
else
{
// revoke a role from a user
JetspeedSecurity.unjoinGroup( user.getUserName(),
((Group)groups.get(ix)).getName() );
}
}
}
// clear the temp values
rundata.getUser().setTemp(SecurityConstants.CONTEXT_GROUPS, null);
rundata.getUser().setTemp(SecurityConstants.CONTEXT_SELECTED, null);
}
catch (Exception e)
{
// log the error msg
logger.error("Failed update role+permission: ", e);
//
// error on update - display error message
//
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, "UserGroupForm");
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
if (user != null)
duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, user.getUserName());
rundata.setRedirectURI(duri.toString());
}
}