1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* distributed under the License is distributed on an "AS IS" BASIS,13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14* See the License for the specific language governing permissions and15* limitations under the License.16*/17packageorg.apache.jetspeed.security.impl.ext;
1819import java.security.Principal;
20import java.security.acl.Group;
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.Enumeration;
24import java.util.List;
2526import javax.security.auth.Subject;
2728import org.apache.jetspeed.security.User;
29import org.apache.jetspeed.security.UserManager;
30import org.apache.jetspeed.security.impl.DefaultLoginModule;
31import org.apache.jetspeed.security.impl.RolePrincipalImpl;
3233/***34 * <p>Configures Subject principals for JBoss JAAS implementation35 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>36 */37publicclassJBossLoginModuleextendsDefaultLoginModule38 {
39privatestaticclass JBossGroup implements Group
40 {
41private String name;
42private ArrayList members = new ArrayList();
4344public JBossGroup(String name, List members)
45 {
46this.name = name;
47this.members.addAll(members);
48 }
4950publicboolean addMember(Principal user)
51 {
52if ( !isMember(user) )
53 {
54 members.add(user);
55returntrue;
56 }
57return false;
58 }
5960publicboolean isMember(Principal member)
61 {
62return members.contains(member);
63 }
6465publicboolean removeMember(Principal user)
66 {
67return members.remove(user);
68 }
6970public Enumeration members()
71 {
72return Collections.enumeration(members);
73 }
7475public String getName()
76 {
77return name;
78 }
79 }
8081/***82 * Create a new JBoss login module83 */84publicJBossLoginModule () {
85super ();
86 }
8788/***89 * Create a new JBoss login module that uses the given user manager.90 * @param userManager91 * @see DefaultLoginModule#DefaultLoginModule(UserManager)92 */93protectedJBossLoginModule (UserManager userManager) {
94super (userManager);
95 }
9697protectedvoid commitPrincipals(Subject subject, User user)
98 {
99// add UserPrincipal to subject100 subject.getPrincipals().add(getUserPrincipal(user));
101 JBossGroup roles = new JBossGroup("Roles", getUserRoles(user));
102 roles.addMember(newRolePrincipalImpl(portalUserRole));
103 subject.getPrincipals().add(roles);
104 }
105 }