1 16 17 package org.apache.jetspeed.modules.actions.portlets.security; 18 19 import org.apache.jetspeed.modules.actions.portlets.SecureVelocityPortletAction; 21 import org.apache.jetspeed.om.security.Group; 22 import org.apache.jetspeed.om.security.JetspeedGroupFactory; 23 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 24 import org.apache.jetspeed.services.JetspeedSecurity; 25 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 26 import org.apache.jetspeed.services.logging.JetspeedLogger; 27 import org.apache.jetspeed.services.resources.JetspeedResources; 28 import org.apache.jetspeed.services.security.GroupException; 29 import org.apache.turbine.util.DynamicURI; 30 import org.apache.turbine.util.RunData; 31 import org.apache.turbine.util.StringUtils; 32 import org.apache.velocity.context.Context; 33 34 35 41 42 public class GroupUpdateAction extends SecureVelocityPortletAction 43 { 44 private static final String TEMP_GROUP = "tempGroup"; 45 46 49 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(GroupUpdateAction.class.getName()); 50 51 58 protected void buildMaximizedContext( VelocityPortlet portlet, 59 Context context, 60 RunData rundata ) 61 { 62 buildNormalContext( portlet, context, rundata); 63 } 64 65 73 protected void buildConfigureContext( VelocityPortlet portlet, 74 Context context, 75 RunData rundata ) 76 { 77 78 buildNormalContext( portlet, context, rundata); 79 } 80 81 88 protected void buildNormalContext( VelocityPortlet portlet, 89 Context context, 90 RunData rundata ) 91 { 92 try 93 { 94 Group group = null; 95 96 99 String mode = rundata.getParameters().getString(SecurityConstants.PARAM_MODE); 100 101 if (mode != null && (mode.equals(SecurityConstants.PARAM_MODE_UPDATE) || 104 mode.equals(SecurityConstants.PARAM_MODE_DELETE))) 105 { 106 String groupname = rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID); 108 group = JetspeedSecurity.getGroup(groupname); 109 context.put(SecurityConstants.CONTEXT_GROUP, group); 110 } 111 112 String msgid = rundata.getParameters().getString(SecurityConstants.PARAM_MSGID); 116 if (msgid != null) 117 { 118 int id = Integer.parseInt(msgid); 119 if (id < SecurityConstants.MESSAGES.length) 120 context.put(SecurityConstants.PARAM_MSG, SecurityConstants.MESSAGES[id]); 121 122 Group tempGroup = (Group)rundata.getUser().getTemp(TEMP_GROUP); 124 if (tempGroup != null) 125 context.put(SecurityConstants.CONTEXT_GROUP, tempGroup); 126 } 127 context.put(SecurityConstants.PARAM_MODE, mode); 128 129 } 130 catch (Exception e) 131 { 132 logger.error("Error in Jetspeed User Security", e); 133 rundata.setMessage("Error in Jetspeed User Security: " + e.toString()); 134 rundata.setStackTrace(StringUtils.stackTrace(e), e); 135 rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error")); 136 } 137 } 138 139 145 public void doInsert(RunData rundata, Context context) 146 throws Exception 147 { 148 Group group = null; 149 try 150 { 151 String name = rundata.getParameters().getString("name"); 155 if (name == null || name.trim().length() == 0) 156 { 157 DynamicURI duri = new DynamicURI (rundata); 158 duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_GROUP_UPDATE); 159 duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_INVALID_ENTITY_NAME); 160 rundata.setRedirectURI(duri.toString()); 161 rundata.getUser().setTemp(TEMP_GROUP, null); 162 return; 163 } 164 165 group = JetspeedGroupFactory.getInstance(); 169 group.setName(name); 170 171 JetspeedSecurity.addGroup(group); 175 176 } 177 catch (GroupException e) 178 { 179 logger.error("Exception", e); 181 182 DynamicURI duri = new DynamicURI (rundata); 186 duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_GROUP_UPDATE); 187 duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_ENTITY_ALREADY_EXISTS); 188 rundata.setRedirectURI(duri.toString()); 189 190 if (group != null) 192 rundata.getUser().setTemp(TEMP_GROUP, group); 193 } 194 } 195 196 202 public void doUpdate(RunData rundata, Context context) 203 throws Exception 204 { 205 Group group = null; 206 try 207 { 208 group = JetspeedSecurity.getGroup( 212 rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID)); 213 214 JetspeedSecurity.saveGroup(group); 218 219 } 220 catch (Exception e) 221 { 222 logger.error("Exception", e); 224 225 DynamicURI duri = new DynamicURI (rundata); 229 duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_GROUP_UPDATE); 230 duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_UPDATE_FAILED); 231 if (group != null) 232 duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, group.getName()); 233 duri.addQueryData(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_UPDATE); 234 rundata.setRedirectURI(duri.toString()); 235 236 if (group != null) 238 rundata.getUser().setTemp(TEMP_GROUP, group); 239 240 } 241 } 242 243 249 public void doDelete(RunData rundata, Context context) 250 throws Exception 251 { 252 Group group = null; 253 254 try 255 { 256 group = JetspeedSecurity.getGroup( 260 rundata.getParameters().getString( SecurityConstants.PARAM_ENTITY_ID) ); 261 262 JetspeedSecurity.removeGroup(group.getName()); 266 267 } 268 catch (Exception e) 269 { 270 logger.error("Exception", e); 272 273 DynamicURI duri = new DynamicURI (rundata); 277 duri.addPathInfo(SecurityConstants.PANE_NAME, SecurityConstants.PANEID_GROUP_UPDATE); 278 duri.addPathInfo(SecurityConstants.PARAM_MSGID, SecurityConstants.MID_DELETE_FAILED); 279 if (group != null) 280 duri.addPathInfo(SecurityConstants.PARAM_ENTITY_ID, group.getName()); 281 duri.addQueryData(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_DELETE); 282 rundata.setRedirectURI(duri.toString()); 283 284 if (group != null) 286 rundata.getUser().setTemp(TEMP_GROUP, group); 287 288 } 289 290 } 291 292 293 294 } 295 | Popular Tags |