1 13 package info.magnolia.module.admininterface.dialogs; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.core.ItemType; 18 import info.magnolia.cms.core.Path; 19 import info.magnolia.cms.gui.dialog.Dialog; 20 import info.magnolia.module.admininterface.SaveHandler; 21 import info.magnolia.module.admininterface.pages.RolesACLPage; 22 23 import java.util.Iterator ; 24 25 import javax.jcr.RepositoryException; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.commons.lang.StringUtils; 30 import org.slf4j.Logger; 31 import org.slf4j.LoggerFactory; 32 33 34 38 public class RolesEditDialog extends ConfiguredDialog { 39 40 protected static Logger log = LoggerFactory.getLogger("roles dialog"); 42 45 private static final long serialVersionUID = 222L; 46 47 53 public RolesEditDialog(String name, HttpServletRequest request, HttpServletResponse response, Content configNode) { 54 super(name, request, response, configNode); 55 } 56 57 public String getRepository() { 58 String repository = super.getRepository(); 59 if (repository == null) { 60 repository = ContentRepository.USER_ROLES; 61 } 62 return repository; 63 } 64 65 70 protected Dialog createDialog(Content configNode, Content storageNode) throws RepositoryException { 71 72 Dialog dialog = super.createDialog(configNode, storageNode); 73 74 dialog.setJavascriptSources(request.getContextPath() + "/.resources/admin-js/dialogs/DynamicTable.js"); dialog.setJavascriptSources(request.getContextPath() + "/.resources/admin-js/dialogs/pages/rolesACLPage.js"); dialog.setCssSources(request.getContextPath() + "/.resources/admin-css/dialogs/pages/rolesEditPage.css"); return dialog; 78 } 79 80 83 protected void configureSaveHandler(SaveHandler save) { 84 super.configureSaveHandler(save); 85 save.setPath(path); 86 } 87 88 protected boolean onPostSave(SaveHandler saveControl) { 89 Content role = this.getStorageNode(); 90 91 Iterator repositoryNames = ContentRepository.getAllRepositoryNames(); 93 while (repositoryNames.hasNext()) { 94 String repository = (String ) repositoryNames.next(); 95 96 try { 101 role.delete("acl_" + repository); } 103 catch (RepositoryException re) { 104 } 106 try { 108 Content acl = role.createContent("acl_" + repository, ItemType.CONTENTNODE); String aclValueStr = form.getParameter("acl" + repository + "List"); if (StringUtils.isNotEmpty(aclValueStr)) { 111 String [] aclEntries = aclValueStr.split(";"); for (int i = 0; i < aclEntries.length; i++) { 113 String path = StringUtils.EMPTY; 114 long accessRight = 0; 115 int accessType = 0; 116 117 String [] aclValuePairs = aclEntries[i].split(","); for (int j = 0; j < aclValuePairs.length; j++) { 119 String [] aclValuePair = aclValuePairs[j].split(":"); String aclName = aclValuePair[0].trim(); 121 String aclValue = StringUtils.EMPTY; 122 if (aclValuePair.length > 1) { 123 aclValue = aclValuePair[1].trim(); 124 } 125 126 if (aclName.equals("path")) { path = aclValue; 128 } 129 else if (aclName.equals("accessType")) { accessType = Integer.valueOf(aclValue).intValue(); 131 } 132 else if (aclName.equals("accessRight")) { try { 134 accessRight = Long.parseLong(aclValue); 135 } 136 catch (NumberFormatException e) { 137 accessRight = 0; 138 } 139 } 140 } 141 142 if (StringUtils.isNotEmpty(path)) { 143 if (path.equals("/")) { accessType = RolesACLPage.TYPE_SUBS; 145 path = StringUtils.EMPTY; 146 } 147 148 if ((accessType & RolesACLPage.TYPE_THIS) != 0) { 149 try { 150 String newLabel = Path.getUniqueLabel(hm, acl.getHandle(), "0"); Content r = acl.createContent(newLabel, ItemType.CONTENTNODE); 152 r.createNodeData("path").setValue(path); r.createNodeData("permissions").setValue(accessRight); } 155 catch (Exception e) { 156 log.error(e.getMessage(), e); 157 } 158 } 159 160 if ((accessType & RolesACLPage.TYPE_SUBS) != 0) { 161 try { 162 String newLabel = Path.getUniqueLabel(hm, acl.getHandle(), "0"); Content r = acl.createContent(newLabel, ItemType.CONTENTNODE); 164 r.createNodeData("path").setValue(path + "/*"); r.createNodeData("permissions").setValue(accessRight); } 167 catch (Exception e) { 168 log.error(e.getMessage(), e); 169 } 170 } 171 } 172 } 173 } 174 hm.save(); 175 } 176 catch (RepositoryException re) { 177 log.error(re.getMessage(), re); 178 } 179 } 180 return true; 181 } 182 183 } | Popular Tags |