KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author Sameer Charles $Id: MgnlGroupManager.java 7706 2006-12-07 17:02:40Z gjoseph $
27  */

28 public class MgnlGroupManager implements GroupManager {
29
30     public static Logger log = LoggerFactory.getLogger(MgnlRoleManager.class);
31
32     /**
33      * Create a group
34      * @param name
35      * @return newly created group
36      * @throws UnsupportedOperationException if the implementation does not support writing
37      * @throws AccessDeniedException if logged in repository user does not sufficient rights
38      */

39     public Group createGroup(String JavaDoc name) throws UnsupportedOperationException JavaDoc, AccessDeniedException {
40         try {
41             Content node = getHierarchyManager().createContent("/", name, ItemType.GROUP.getSystemName());
42             getHierarchyManager().save();
43             return new MgnlGroup(node);
44         }
45         catch (Exception JavaDoc e) {
46             log.error("can't create role [" + name + "]", e);
47             return null;
48         }
49     }
50
51     /**
52      * Get group by the given name
53      * @param name
54      * @return group
55      * @throws UnsupportedOperationException if the implementation does not support writing
56      * @throws AccessDeniedException if logged in repository user does not sufficient rights
57      */

58     public Group getGroup(String JavaDoc name) throws UnsupportedOperationException JavaDoc, AccessDeniedException {
59         try {
60             return new MgnlGroup(getHierarchyManager().getContent(name));
61         }
62         catch (Exception JavaDoc e) {
63             log.info("can't find group [" + name + "]", e);
64             return null;
65         }
66     }
67
68     /**
69      * return the role HierarchyManager
70      */

71     protected HierarchyManager getHierarchyManager() {
72         return MgnlContext.getHierarchyManager(ContentRepository.USER_GROUPS);
73     }
74 }
75
Popular Tags