1 package info.magnolia.module.admininterface.dialogs; 2 3 import info.magnolia.cms.beans.config.ContentRepository; 4 import info.magnolia.cms.core.Content; 5 import info.magnolia.cms.core.ItemType; 6 import info.magnolia.cms.core.Path; 7 import info.magnolia.cms.gui.control.Save; 8 import info.magnolia.cms.gui.dialog.DialogBox; 9 import info.magnolia.cms.gui.dialog.DialogDialog; 10 import info.magnolia.cms.gui.dialog.DialogEdit; 11 import info.magnolia.cms.gui.dialog.DialogFactory; 12 import info.magnolia.cms.gui.dialog.DialogInclude; 13 import info.magnolia.cms.gui.dialog.DialogStatic; 14 import info.magnolia.cms.gui.dialog.DialogTab; 15 16 import javax.jcr.RepositoryException; 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.HttpServletResponse ; 19 20 import org.apache.commons.lang.StringUtils; 21 import org.apache.log4j.Logger; 22 23 24 28 public class UserRolesEditDialog extends ConfiguredDialog { 29 30 protected static Logger log = Logger.getLogger("roles dialog"); 32 35 private static final long serialVersionUID = 222L; 36 37 43 public UserRolesEditDialog(String name, HttpServletRequest request, HttpServletResponse response, Content configNode) { 44 super(name, request, response, configNode); 45 } 46 47 public String getRepository() { 48 String repository = super.getRepository(); 49 if (repository == null) { 50 repository = ContentRepository.USER_ROLES; 51 } 52 return repository; 53 } 54 55 60 protected DialogDialog createDialog(Content configNode, Content storageNode) throws RepositoryException { 61 62 DialogDialog dialog = super.createDialog(configNode, storageNode); 63 64 dialog.setJavascriptSources(request.getContextPath() + "/admindocroot/js/dialogs/DynamicTable.js"); dialog.setJavascriptSources(request.getContextPath() 66 + "/admindocroot/js/dialogs/pages/userRolesEditDialogPage.js"); dialog.setCssSources(request.getContextPath() + "/admindocroot/css/dialogs/pages/userRolesEditDialogPage.css"); dialog.setConfig("height", 600); 70 dialog.setLabel(msgs.get("roles.edit.edit")); 72 DialogTab tab0 = dialog.addTab(msgs.get("roles.edit.properties")); 74 DialogTab tab1 = dialog.addTab(msgs.get("roles.edit.accessControlList")); 76 DialogStatic spacer = DialogFactory.getDialogStaticInstance(request, response, null, null); 77 spacer.setConfig("line", false); 79 DialogStatic name = DialogFactory.getDialogStaticInstance(request, response, null, null); 80 name.setLabel("<strong>" + msgs.get("roles.edit.rolename") + "</strong>"); name.setValue("<strong>" + storageNode.getName() + "</strong>"); tab0.addSub(name); 84 85 tab0.addSub(spacer); 86 87 DialogEdit title = DialogFactory.getDialogEditInstance(request, response, storageNode, null); 88 title.setName("title"); title.setLabel(msgs.get("roles.edit.fullname")); tab0.addSub(title); 91 92 tab0.addSub(spacer); 93 94 DialogEdit desc = DialogFactory.getDialogEditInstance(request, response, storageNode, null); 95 desc.setName("description"); desc.setLabel(msgs.get("roles.edit.description")); desc.setConfig("rows", 6); tab0.addSub(desc); 99 100 DialogInclude acl = DialogFactory.getDialogIncludeInstance(request, response, storageNode, null); 101 acl.setBoxType(DialogBox.BOXTYPE_1COL); 102 acl.setName("aclRolesRepository"); acl.setConfig("file", "/.magnolia/dialogpages/userRolesEditAclInclude.html"); tab1.addSub(acl); 105 106 dialog.setConfig("saveOnclick", "aclFormSubmit();"); return dialog; 108 } 109 110 114 protected Save onPreSave() { 115 Save control = super.onPreSave(); 116 control.setPath(path); 117 return control; 118 } 119 120 protected void onPostSave(Save saveControl) { 121 Content role = this.getStorageNode(); 122 123 for (int x = 0; x < ContentRepository.getAllRepositoryNames().length; x++) { 125 String repository = ContentRepository.getAllRepositoryNames()[x]; 126 127 try { 132 role.delete("acl_" + repository); } 134 catch (RepositoryException re) { 135 } 137 try { 139 Content acl = role.createContent("acl_" + repository, ItemType.CONTENTNODE); String aclValueStr = form.getParameter("acl" + repository + "List"); if (StringUtils.isNotEmpty(aclValueStr)) { 142 String [] aclEntries = aclValueStr.split(";"); for (int i = 0; i < aclEntries.length; i++) { 144 String path = StringUtils.EMPTY; 145 long accessRight = 0; 146 String accessType = StringUtils.EMPTY; 147 148 String [] aclValuePairs = aclEntries[i].split(","); for (int j = 0; j < aclValuePairs.length; j++) { 150 String [] aclValuePair = aclValuePairs[j].split(":"); String aclName = aclValuePair[0].trim(); 152 String aclValue = StringUtils.EMPTY; 153 if (aclValuePair.length > 1) { 154 aclValue = aclValuePair[1].trim(); 155 } 156 157 if (aclName.equals("path")) { path = aclValue; 159 } 160 else if (aclName.equals("accessType")) { accessType = aclValue; 162 } 163 else if (aclName.equals("accessRight")) { try{ 165 accessRight = Long.parseLong(aclValue); 166 } 167 catch(NumberFormatException e){ 168 accessRight = 0; 169 } 170 } 171 } 172 173 if (StringUtils.isNotEmpty(path)) { 174 if (path.equals("/")) { accessType = "sub"; path = StringUtils.EMPTY; 178 } 179 180 if (accessType.equals("self")) { try { 182 String newLabel = Path.getUniqueLabel(hm, acl.getHandle(), "0"); Content r = acl.createContent(newLabel, ItemType.CONTENTNODE); 184 r.createNodeData("path").setValue(path); r.createNodeData("permissions").setValue(accessRight); } 187 catch (Exception e) { 188 log.error(e.getMessage(), e); 189 } 190 } 191 try { 192 String newLabel = Path.getUniqueLabel(hm, acl.getHandle(), "0"); Content r = acl.createContent(newLabel, ItemType.CONTENTNODE); 194 r.createNodeData("path").setValue(path + "/*"); r.createNodeData("permissions").setValue(accessRight); } 197 catch (Exception e) { 198 log.error(e.getMessage(), e); 199 } 200 } 201 } 202 } 203 hm.save(); 204 } 205 catch (RepositoryException re) { 206 log.error(re.getMessage(), re); 207 } 208 } 209 } 210 211 } | Popular Tags |