KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > ejb > UsersRoles2LoginModule


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.ejb;
23
24 import java.security.acl.Group JavaDoc;
25 import java.security.Principal JavaDoc;
26 import java.util.Enumeration JavaDoc;
27
28 import javax.security.auth.login.LoginException JavaDoc;
29
30 import org.jboss.security.auth.spi.UsersRolesLoginModule;
31 import org.jboss.security.SimpleGroup;
32 import org.jboss.security.SimplePrincipal;
33
34 /** A simple override of UsersRolesLoginModule used to test security domain
35  * traversal. This simulates trust based on the same passwords with the
36  * roles of the second domain being distinct modifications of the first
37  * domains roles.
38  *
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 37406 $
41  */

42 public class UsersRoles2LoginModule extends UsersRolesLoginModule
43 {
44    /**
45     * Override to add '2' to every role name to make the roles different
46     * @throws LoginException
47     */

48    protected Group JavaDoc[] getRoleSets() throws LoginException JavaDoc
49    {
50       Group JavaDoc[] groups = super.getRoleSets();
51       Group JavaDoc[] newGroups = {new SimpleGroup("Roles")};
52       Group JavaDoc roles = null;
53       Group JavaDoc newRoles = newGroups[0];
54       for(int n = 0; n < groups.length; n ++)
55       {
56          Group JavaDoc g = groups[n];
57          if( g.getName().equals("Roles") )
58          {
59             roles = g;
60             break;
61          }
62       }
63       if( roles != null )
64       {
65          Enumeration JavaDoc iter = roles.members();
66          Principal JavaDoc role = (Principal JavaDoc) iter.nextElement();
67          String JavaDoc name2 = role.getName() + "2";
68          SimplePrincipal role2 = new SimplePrincipal(name2);
69          newRoles.addMember(role2);
70       }
71       return newGroups;
72    }
73 }
74
Popular Tags