1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.impl.ext;
18
19 import java.security.Principal;
20 import java.security.acl.Group;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Enumeration;
24 import java.util.List;
25
26 import javax.security.auth.Subject;
27
28 import org.apache.jetspeed.security.User;
29 import org.apache.jetspeed.security.UserManager;
30 import org.apache.jetspeed.security.impl.DefaultLoginModule;
31 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
32
33 /***
34 * <p>Configures Subject principals for JBoss JAAS implementation
35 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
36 */
37 public class JBossLoginModule extends DefaultLoginModule
38 {
39 private static class JBossGroup implements Group
40 {
41 private String name;
42 private ArrayList members = new ArrayList();
43
44 public JBossGroup(String name, List members)
45 {
46 this.name = name;
47 this.members.addAll(members);
48 }
49
50 public boolean addMember(Principal user)
51 {
52 if ( !isMember(user) )
53 {
54 members.add(user);
55 return true;
56 }
57 return false;
58 }
59
60 public boolean isMember(Principal member)
61 {
62 return members.contains(member);
63 }
64
65 public boolean removeMember(Principal user)
66 {
67 return members.remove(user);
68 }
69
70 public Enumeration members()
71 {
72 return Collections.enumeration(members);
73 }
74
75 public String getName()
76 {
77 return name;
78 }
79 }
80
81 /***
82 * Create a new JBoss login module
83 */
84 public JBossLoginModule () {
85 super ();
86 }
87
88 /***
89 * Create a new JBoss login module that uses the given user manager.
90 * @param userManager
91 * @see DefaultLoginModule#DefaultLoginModule(UserManager)
92 */
93 protected JBossLoginModule (UserManager userManager) {
94 super (userManager);
95 }
96
97 protected void commitPrincipals(Subject subject, User user)
98 {
99
100 subject.getPrincipals().add(getUserPrincipal(user));
101 JBossGroup roles = new JBossGroup("Roles", getUserRoles(user));
102 roles.addMember(new RolePrincipalImpl(portalUserRole));
103 subject.getPrincipals().add(roles);
104 }
105 }