hi, I am using the following velocity macro for role updation:
========================================================================== -user-role-form.vm- #** @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> @version $Id: user-role-form.vm,v 1.1.1.1 2003/10/22 03:24:59 ssheshad Exp $ *# <h3>Roles for $user.FirstName $user.LastName<h3> #set ( $headings = ["Role Name", "Assign"] ) <form method="post" action="$jslink.getPaneByName("UserBrowser").addPathInfo($jslink.ActionKey," portlets.security.UserRoleUpdateAction")"> <table> <tr> <td> <table border="true" cellspacing="1" cellpadding="3"> <tr> #foreach ($heading in $headings) #headerCell ($heading) #end </tr> #foreach ($role in $roles) <tr> #entryCell ($role.Name) #formCheckBox ($role.Name $selected.elementAt($velocityCount).booleanValue()) </tr> #end </table> </td> </tr> <tr> <td> <input type="submit" name="eventSubmit_doUpdate" value="Update"/> <td> <td> $!msg </td> </tr> </table> <input type="hidden" name="entityid" value="$!user.UserName"/> </form> ========================================================================== This macro submits to class "org.apache.jetspeed.modules.actions.portlets.security.UserRoleUpdateAction" . Following is the code for UserRoleUpdateAction class: /* UserRoleUpdateAction Class*/ package org.apache.jetspeed.modules.actions.portlets.security; import java.util.*; import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction; import org.apache.jetspeed.om.security.Role; import org.apache.jetspeed.portal.portlets.VelocityPortlet; import org.apache.jetspeed.services.JetspeedSecurity; import org.apache.jetspeed.services.resources.JetspeedResources; import org.apache.turbine.om.security.User; import org.apache.turbine.util.*; import org.apache.velocity.context.Context; // Referenced classes of package org.apache.jetspeed.modules.actions.portlets.security: // SecurityConstants public class UserRoleUpdateAction extends VelocityPortletAction { public UserRoleUpdateAction() { } protected void buildMaximizedContext(VelocityPortlet portlet, Context context, RunData rundata) { buildNormalContext(portlet, context, rundata); } protected void buildConfigureContext(VelocityPortlet portlet, Context context, RunData rundata) { buildNormalContext(portlet, context, rundata); } protected void buildNormalContext(VelocityPortlet portlet, Context context, RunData rundata) { try { Role role = null; String mode = rundata.getParameters().getString("mode"); String entityid = rundata.getParameters().getString("entityid"); if(entityid == null || entityid.trim().length() == 0) return; buildUserRoleContext(portlet, context, rundata, entityid); String msgid = rundata.getParameters().getString("msgid"); if(msgid != null) { int id = Integer.parseInt(msgid); if(id < SecurityConstants.MESSAGES.length) context.put("msg", SecurityConstants.MESSAGES[id]); } } catch(Exception e) { Log.error(e); rundata.setMessage("Error in Jetspeed User Role Security: " + e.toString()); rundata.setStackTrace(StringUtils.stackTrace(e), e); rundata.setScreenTemplate(JetspeedResources.getString("template.error", "Error")); } } public void doUpdate(RunData rundata, Context context) throws Exception { String entityid = rundata.getParameters().getString("entityid"); if(entityid == null || entityid.trim().length() == 0) { Log.error("UserRoleBrowser: Failed to get entity: " + entityid); DynamicURI duri = new DynamicURI(rundata); duri.addPathInfo("js_panename", "UserRoleForm"); duri.addPathInfo("msgid", 5); rundata.setRedirectURI(duri.toString()); return; } org.apache.jetspeed.om.security.JetspeedUser user = JetspeedSecurity.getUser(entityid); if(null == user) { Log.error("UserRoleBrowser: Failed to get user: " + entityid); DynamicURI duri = new DynamicURI(rundata); duri.addPathInfo("js_panename", "UserRoleForm"); duri.addPathInfo("msgid", 5); rundata.setRedirectURI(duri.toString()); return; } try { List roles = (List)rundata.getUser().getTemp("roles"); List selected = (List)rundata.getUser().getTemp("selected"); if(roles == null || selected == null) { DynamicURI duri = new DynamicURI(rundata); duri.addPathInfo("js_panename", "UserRoleForm"); duri.addPathInfo("msgid", 5); rundata.setRedirectURI(duri.toString()); return; } 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(); if(newValue != oldValue) if(newValue) JetspeedSecurity.grantRole(user.getUserName(), ((Role)roles.get(ix)).getName()); else JetspeedSecurity.revokeRole(user.getUserName(), ((Role)roles.get(ix)).getName()); } rundata.getUser().setTemp("roles", null); rundata.getUser().setTemp("selected", null); } catch(Exception e) { Log.error("Failed update role+permission: " + e); //This excepion is being caught in the application. DynamicURI duri = new DynamicURI(rundata); duri.addPathInfo("js_panename", "UserRoleForm"); duri.addPathInfo("msgid", 0); if(user != null) duri.addPathInfo("entityid", user.getUserName()); rundata.setRedirectURI(duri.toString()); } } private void buildUserRoleContext(VelocityPortlet portlet, Context context, RunData rundata, String userid) throws Exception { org.apache.jetspeed.om.security.JetspeedUser user = JetspeedSecurity.getUser(userid); if(null == user) { Log.error("UserRoleBrowser: Failed to get user: " + userid); return; } Iterator roles = JetspeedSecurity.getRoles(); Vector masterRoles = new Vector(); Vector selected = new Vector(); int ix = 0; boolean sel = false; selected.add(ix, new Boolean(sel)); for(; roles.hasNext(); selected.add(ix, new Boolean(sel))) { Role role = (Role)roles.next(); masterRoles.add(role); sel = JetspeedSecurity.hasRole(user.getUserName(), role.getName()); ix++; } masterRoles.trimToSize(); selected.trimToSize(); rundata.getUser().setTemp("roles", masterRoles); rundata.getUser().setTemp("selected", selected); context.put("user", user); context.put("roles", masterRoles); context.put("selected", selected); } } ============================================================================ If anything else is required, please let me know that. Thanks. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 7:41 PM To: Jetspeed Users List; [EMAIL PROTECTED] Subject: Re: Role Updation Error Send the code you are using so we can have a look at it. Quoting Nagesh Mittal <[EMAIL PROTECTED]>: ** hi, ** ** I am using Jetspeed 1.4-b4 in my portal application. ** When I try to update the roles for a user, I get the following exception: ** ** [02 Mar 2004 07:00:47 ERROR] - Failed update role+permission: ** java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 ** ** Any idea about how to tackle this problem? ** ** Also, I am getting another error: ** ** [15 Mar 2004 12:31:58 ERROR] - Error rendering Velocity template: ** layouts/psf.vm: Unable to find resource 'layouts/psf.vm' ** org.apache.velocity.exception.ResourceNotFoundException: Unable to find ** resource 'layouts/psf.vm' ** at ** org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Resour ** ceManagerImpl.java:501) ** at ** org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Resourc ** eManagerImpl.java:384) ** at ** org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java ** :814) ** at ** org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.ja ** va:355) ** at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:482) ** at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:461) ** rethrown as ** org.apache.turbine.util.TurbineException: Error rendering Velocity ** template: layouts/psf.vm: Unable to find resource 'layouts/psf.vm' ** ............................................ ** ............................................ ** ............................................ ** ** ** Thanks in advance. ** ** Kind Regards, ** ** Nagesh Mittal ** ** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
