KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > plugins > NullSecurityManager


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.security.plugins;
8
9 import java.io.Serializable JavaDoc;
10 import java.util.HashSet JavaDoc;
11 import java.util.Set JavaDoc;
12 import java.security.Principal JavaDoc;
13 import javax.security.auth.Subject JavaDoc;
14
15 import org.jboss.security.AnybodyPrincipal;
16 import org.jboss.security.RealmMapping;
17 import org.jboss.security.SubjectSecurityManager;
18
19
20 /** An implementation of SubjectSecurityManager, RealmMapping that authenticates
21 everyone and for which Principals have any role requested. It can be used
22 as a pass-through security manager when you want noop security.
23
24 @see #isValid(Principal, Object, Subject)
25 @see #getPrincipal(Principal)
26 @see #doesUserHaveRole(Principal, Set)
27
28 @author Scott.Stark@jboss.org
29 @version $Revision: 1.7.4.2 $
30 */

31 public class NullSecurityManager
32     implements SubjectSecurityManager, RealmMapping, Serializable JavaDoc
33 {
34     static final long serialVersionUID = -5942994627247826747L;
35     private String JavaDoc securityDomain;
36
37     /** Creates a default JaasSecurityManager for with the
38         given securityDomain name.
39     */

40     public NullSecurityManager(String JavaDoc securityDomain)
41     {
42         this.securityDomain = securityDomain;
43     }
44
45     /** Get the name of the security domain associated with this security mgr.
46         @return Name of the security manager security domain.
47      */

48     public String JavaDoc getSecurityDomain()
49     {
50         return securityDomain;
51     }
52     /** Get the currently authenticated Subject.
53         @return Always returns null.
54      */

55     public Subject JavaDoc getActiveSubject()
56     {
57         return null;
58     }
59
60     /** Validate that the given credential is correct for principal.
61     @return always returns true.
62      */

63     public boolean isValid(Principal JavaDoc principal, Object JavaDoc credential)
64     {
65         return true;
66     }
67     /** Validate that the given credential is correct for principal. This does
68      not populate the activeSubject with any state since no authentication
69      is performed.
70     @return always returns true.
71      */

72     public boolean isValid(Principal JavaDoc principal, Object JavaDoc credential,
73       Subject JavaDoc activeSubject)
74     {
75        return true;
76     }
77
78     /** Always returns the argument principal.
79     @return The argument principal
80      */

81     public Principal JavaDoc getPrincipal(Principal JavaDoc principal)
82     {
83         Principal JavaDoc result = principal;
84         return result;
85     }
86
87     /** Does the current Subject have a role(a Principal) that equates to one
88         of the role names. This method always returns true.
89     @param principal - ignored.
90     @param roleNames - ignored.
91     @return Always returns true.
92     */

93     public boolean doesUserHaveRole(Principal JavaDoc principal, Set JavaDoc roleNames)
94     {
95         boolean hasRole = true;
96         return hasRole;
97     }
98
99     /** Return the set of domain roles the principal has been assigned.
100     @return The Set<Principal> with the AnybodyPrincipal as the sole role.
101      */

102     public Set JavaDoc getUserRoles(Principal JavaDoc principal)
103     {
104         HashSet JavaDoc roles = new HashSet JavaDoc();
105         roles.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
106         return roles;
107     }
108
109     /** Authenticate principal against credential
110      * @param principal - the user id to authenticate
111      * @param credential - an opaque credential.
112      * @return Always returns true.
113      */

114     private boolean authenticate(Principal JavaDoc principal, Object JavaDoc credential)
115     {
116         boolean authenticated = true;
117         return authenticated;
118     }
119 }
120
Popular Tags