KickJava   Java API By Example, From Geeks To Geeks.

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


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.HierarchyManager;
17
18 import java.util.Collection JavaDoc;
19
20 import javax.security.auth.Subject JavaDoc;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26 /**
27  * Manages the JAAS users.
28  * @author philipp
29  * @version $Revision: 6341 $ ($Author: philipp $)
30  */

31 public class ExternalUserManager implements UserManager {
32
33     /**
34      * Logger
35      */

36     public static Logger log = LoggerFactory.getLogger(MgnlUserManager.class);
37
38     public User getUser(String JavaDoc name) throws UnsupportedOperationException JavaDoc {
39         throw new UnsupportedOperationException JavaDoc("not implemented yet");
40     }
41
42     public Collection JavaDoc getAllUsers() throws UnsupportedOperationException JavaDoc {
43         throw new UnsupportedOperationException JavaDoc("not implemented yet");
44     }
45
46     public User createUser(String JavaDoc name, String JavaDoc pw) throws UnsupportedOperationException JavaDoc {
47         throw new UnsupportedOperationException JavaDoc("not implemented yet");
48     }
49
50     /**
51      * Initialize new user using JAAS authenticated/authorized subject
52      * @param subject
53      * @throws UnsupportedOperationException
54      */

55     public User getUser(Subject JavaDoc subject) throws UnsupportedOperationException JavaDoc {
56         return new ExternalUser(subject);
57     }
58
59     /**
60      * Get system user, this user must always exist in magnolia repository.
61      * @return system user
62      */

63     public User getSystemUser() {
64         try {
65             return new MgnlUser(getHierarchyManager().getContent(UserManager.SYSTEM_USER));
66         }
67         catch (Exception JavaDoc e) {
68             log.error("can't find System user", e);
69             log.info("Try to create new system user with default password");
70             return this.createUser(UserManager.SYSTEM_USER, UserManager.SYSTEM_PSWD);
71         }
72     }
73
74     /**
75      * Get Anonymous user, this user must always exist in magnolia repository.
76      * @return anonymous user
77      */

78     public User getAnonymousUser() {
79         try {
80             return new MgnlUser(getHierarchyManager().getContent(UserManager.ANONYMOUS_USER));
81         }
82         catch (Exception JavaDoc e) {
83             log.error("can't find Anonymous user", e);
84             log.info("Try to create new system user with default password");
85             return this.createUser(UserManager.ANONYMOUS_USER, "");
86         }
87     }
88
89     /**
90      * return the user HierarchyManager
91      */

92     protected HierarchyManager getHierarchyManager() {
93         return ContentRepository.getHierarchyManager(ContentRepository.USERS);
94     }
95
96 }
97
Popular Tags