1 13 package info.magnolia.cms.security; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.core.HierarchyManager; 18 import info.magnolia.cms.core.ItemType; 19 import info.magnolia.context.MgnlContext; 20 21 import org.slf4j.Logger; 22 import org.slf4j.LoggerFactory; 23 24 25 30 public class MgnlRoleManager implements RoleManager { 31 32 public static Logger log = LoggerFactory.getLogger(MgnlRoleManager.class); 33 34 37 public MgnlRoleManager() { 38 } 39 40 public Role getRole(String name) { 41 try { 42 return new MgnlRole(getHierarchyManager().getContent(name)); 43 } 44 catch (Exception e) { 45 log.info("can't find role [" + name + "]", e); 46 return null; 47 } 48 } 49 50 public Role createRole(String name) { 51 try { 52 Content node = getHierarchyManager().createContent("/", name, ItemType.ROLE.getSystemName()); 53 getHierarchyManager().save(); 54 return new MgnlRole(node); 55 } 56 catch (Exception e) { 57 log.error("can't create role [" + name + "]", e); 58 return null; 59 } 60 } 61 62 65 protected HierarchyManager getHierarchyManager() { 66 return MgnlContext.getHierarchyManager(ContentRepository.USER_ROLES); 67 } 68 } 69 | Popular Tags |