KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > security > MgnlRoleManager


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

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 /**
26  * Manages the users stored in magnolia itself.
27  * @author philipp
28  * @version $Revision: 7706 $ ($Author: gjoseph $)
29  */

30 public class MgnlRoleManager implements RoleManager {
31
32     public static Logger log = LoggerFactory.getLogger(MgnlRoleManager.class);
33
34     /**
35      * Do not instantiate it!
36      */

37     public MgnlRoleManager() {
38     }
39
40     public Role getRole(String JavaDoc name) {
41         try {
42             return new MgnlRole(getHierarchyManager().getContent(name));
43         }
44         catch (Exception JavaDoc e) {
45             log.info("can't find role [" + name + "]", e);
46             return null;
47         }
48     }
49
50     public Role createRole(String JavaDoc name) {
51         try {
52             Content node = getHierarchyManager().createContent("/", name, ItemType.ROLE.getSystemName());
53             getHierarchyManager().save();
54             return new MgnlRole(node);
55         }
56         catch (Exception JavaDoc e) {
57             log.error("can't create role [" + name + "]", e);
58             return null;
59         }
60     }
61
62     /**
63      * return the role HierarchyManager
64      */

65     protected HierarchyManager getHierarchyManager() {
66         return MgnlContext.getHierarchyManager(ContentRepository.USER_ROLES);
67     }
68 }
69
Popular Tags