duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_MISSING_PARAMETER);
rundata.setRedirectURI(duri.toString());
return;
}
JetspeedUser user = JetspeedSecurity.getUser(entityid);
if (null == user)
{
logger.error("UserRoleBrowser: Failed to get user: " + entityid );
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_USERROLE_UPDATE);
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_MISSING_PARAMETER);
rundata.setRedirectURI(duri.toString());
return;
}
try
{
List roles = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_ROLES);
List selected = (List)rundata.getUser().getTemp(SecurityConstants.CONTEXT_SELECTED);
if (roles == null || selected == null)
{
DynamicURI duri = new DynamicURI (rundata);
duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_USERROLE_UPDATE);
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 < roles.size(); ix++)
{
boolean newValue = rundata.getParameters().getBoolean("box_" + ((Role)roles.get(ix)).getName(), false);
boolean oldValue = ((Boolean)selected.get(ix + 1)).booleanValue();
//System.out.println("In role:"+((Role)roles.get(ix)).getName()+" newValue="+newValue+" oldValue="+oldValue);
if (newValue != oldValue)
{
if (newValue == true)
{
// grant a role to a user
Role newRole = (Role) roles.get(ix);
JetspeedSecurity.grantRole( user.getUserName(), newRole.getName());
// If role profile merging is active, append profile for the new role
if (Profiler.useRoleProfileMerging())
{
appendNewRoleProfile((JetspeedRunData) rundata, user, newRole);
}
}
else
{
// revoke a role from a user
JetspeedSecurity.revokeRole( user.getUserName(),
((Role)roles.get(ix)).getName() );
}
}
}
// clear the temp values
rundata.getUser().setTemp(SecurityConstants.CONTEXT_ROLES, null);
rundata.getUser().setTemp(SecurityConstants.CONTEXT_SELECTED, null);
}
catch (Exception e)
{
// 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, SecurityConstants.PANEID_USERROLE_UPDATE);
duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED);
if (user != null)
duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, user.getUserName());
rundata.setRedirectURI(duri.toString());
}
}