User: starksm 
  Date: 01/04/10 19:04:21

  Modified:    src/main/org/jboss/security/plugins/samples
                        DatabaseServerLoginModule.java
                        IdentityLoginModule.java JaasServerLoginModule.java
                        LdapLoginModule.java RolesLoginModule.java
                        SimpleServerLoginModule.java
                        UsernamePasswordLoginModule.java
  Log:
  Clean up the package structure.
  
  Revision  Changes    Path
  1.3       +5 -188    
jbosssx/src/main/org/jboss/security/plugins/samples/DatabaseServerLoginModule.java
  
  Index: DatabaseServerLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/DatabaseServerLoginModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseServerLoginModule.java    2001/03/29 02:27:12     1.2
  +++ DatabaseServerLoginModule.java    2001/04/11 02:04:21     1.3
  @@ -6,198 +6,15 @@
    */
   package org.jboss.security.plugins.samples;
   
  -import java.security.acl.Group;
  -import java.util.Enumeration;
  -import java.util.HashMap;
  -import java.util.Map;
  -import java.util.Set;
  -import java.util.Vector;
  -import java.sql.Connection;
  -import java.sql.PreparedStatement;
  -import java.sql.ResultSet;
  -import java.sql.SQLException;
  -import javax.naming.InitialContext;
  -import javax.naming.NamingException;
  -import javax.sql.DataSource;
  -import javax.security.auth.Subject;
  -import javax.security.auth.callback.CallbackHandler;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.login.FailedLoginException;
  +/** This module has been renamed to 
org.jboss.security.auth.spi.DatabaseServerLoginModule.
   
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.plugins.samples.UsernamePasswordLoginModule;
  +@deprecated See {@link org.jboss.security.auth.spi.DatabaseServerLoginModule } 
which has replaced this module.
   
  -/** A JDBC based login module that supports authentication and role mapping.
  -It is based on two logical tables:
  -
  - Principals(PrincipalID text, Password text)
  - Roles(PrincipalID text, Role text, RoleGroup text)
  -
  -LoginModule options:
  -dsJndiName: The name of the DataSource of the database containing the Principals, 
Roles tables
  -principalsQuery: The prepared statement query equivalent to:
  -    "select Password from Principals where PrincipalID=?"
  -rolesQuery: The prepared statement query equivalent to:
  -    "select Role, RoleGroup from Roles where PrincipalID=?"
  -
   @author <a href="[EMAIL PROTECTED]">Oleg Nitz</a>
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  +@version $Revision: 1.3 $
   */
  -public class DatabaseServerLoginModule extends UsernamePasswordLoginModule
  +public class DatabaseServerLoginModule
  +    extends org.jboss.security.auth.spi.DatabaseServerLoginModule
   {
  -    private String dsJndiName;
  -    private String principalsQuery = "select Password from Principals where 
PrincipalID=?";
  -    private String rolesQuery = "select Role, RoleGroup from Roles where 
PrincipalID=?";
  -
  -    /**
  -     * Initialize this LoginModule.
  -     */
  -    public void initialize(Subject subject, CallbackHandler callbackHandler, Map 
sharedState, Map options)
  -    {
  -        super.initialize(subject, callbackHandler, sharedState, options);
  -        dsJndiName = (String) options.get("dsJndiName");
  -        Object tmp = options.get("principalsQuery");
  -        if( tmp != null )
  -            principalsQuery = tmp.toString();
  -        tmp = options.get("rolesQuery");
  -        if( tmp != null )
  -            rolesQuery = tmp.toString();
  -    }
  -
  -     /** Get the expected password for the current username available via
  -     * the getUsername() method. This is called from within the login()
  -     * method after the CallbackHandler has returned the username and
  -     * candidate password.
  -     * @return the valid password String
  -     */
  -    protected String getUsersPassword() throws LoginException
  -    {
  -        String username = getUsername();
  -        String password = null;
  -        Connection conn = null;
  -
  -        try
  -        {
  -            InitialContext ctx = new InitialContext();
  -            DataSource ds = (DataSource) ctx.lookup(dsJndiName);
  -            conn = ds.getConnection();
  -            // Get the password
  -            PreparedStatement ps = conn.prepareStatement(principalsQuery);
  -            ps.setString(1, username);
  -            ResultSet rs = ps.executeQuery();
  -            if( rs.next() == false )
  -                throw new FailedLoginException("No matching username found in 
Principals");
  -
  -            password = rs.getString(1);
  -            password = convertRawPassword(password);
  -            ps.close();
  -            rs.close();
  -        }
  -        catch(NamingException ex)
  -        {
  -            throw new LoginException(ex.toString(true));
  -        }
  -        catch(SQLException ex)
  -        {
  -            ex.printStackTrace();
  -            throw new LoginException(ex.toString());
  -        }
  -        finally
  -        {
  -            if( conn != null )
  -            {
  -                try
  -                {
  -                    conn.close();
  -                }
  -                catch (Exception ex)
  -                {
  -                }
  -            }
  -        }
  -        return password;
  -    }
  -
  -    /** Overriden by subclasses to return the Groups that correspond to the
  -        to the role sets assigned to the user. Subclasses should create at
  -        least a Group named "Roles" that contains the roles assigned to the user.
  -        A second common group is "CallerPrincipal" that provides the application
  -        identity of the user rather than the security domain identity.
  -    @return Group[] containing the sets of roles 
  -    */
  -    protected Group[] getRoleSets() throws LoginException
  -    {
  -        String username = getUsername();
  -        Connection conn = null;
  -        HashMap setsMap = new HashMap();
  -
  -        try
  -        {
  -            InitialContext ctx = new InitialContext();
  -            DataSource ds = (DataSource) ctx.lookup(dsJndiName);
  -            conn = ds.getConnection();
  -            // Get the users role names
  -            PreparedStatement ps = conn.prepareStatement(rolesQuery);
  -            ps.setString(1, username);
  -            ResultSet rs = ps.executeQuery();
  -            if( rs.next() == false )
  -                throw new FailedLoginException("No matching username found in 
Roles");
  -
  -            do
  -            {
  -                String name = rs.getString(1);
  -                String groupName = rs.getString(2);
  -                if( groupName == null || groupName.length() == 0 )
  -                    groupName = "Roles";
  -                Group group = (Group) setsMap.get(groupName);
  -                if( group == null )
  -                {
  -                    group = new SimpleGroup(groupName);
  -                    setsMap.put(groupName, group);
  -                }
  -                group.addMember(new SimplePrincipal(name));
  -            } while( rs.next() );
  -            ps.close();
  -            rs.close();
  -        }
  -        catch(NamingException ex)
  -        {
  -            throw new LoginException(ex.toString(true));
  -        }
  -        catch(SQLException ex)
  -        {
  -            ex.printStackTrace();
  -            throw new LoginException(ex.toString());
  -        }
  -        finally
  -        {
  -            if( conn != null )
  -            {
  -                try
  -                {
  -                    conn.close();
  -                }
  -                catch (Exception ex)
  -                {
  -                }
  -            }
  -        }
  -
  -        Group[] roleSets = new Group[setsMap.size()];
  -        setsMap.values().toArray(roleSets);
  -        return roleSets;
  -    }
  -
  -    /** A hook to allow subclasses to convert a password from the database
  -        into a plain text string or whatever form is used for matching against
  -        the user input. It is called from within the getUsersPassword() method.
  -    @param rawPassword, the password as obtained from the database
  -    @return the argument rawPassword
  -    */
  -    protected String convertRawPassword(String rawPassword)
  -    {
  -        return rawPassword;
  -    }
   }
  
  
  
  1.4       +12 -73    
jbosssx/src/main/org/jboss/security/plugins/samples/IdentityLoginModule.java
  
  Index: IdentityLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/IdentityLoginModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IdentityLoginModule.java  2001/03/29 02:27:12     1.3
  +++ IdentityLoginModule.java  2001/04/11 02:04:21     1.4
  @@ -1,81 +1,20 @@
  -
  +/*
  + * JBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.security.plugins.samples;
  -
  -import java.security.Principal;
  -import java.security.acl.Group;
  -import java.util.ArrayList;
  -import java.util.Map;
  -import java.util.StringTokenizer;
  -import javax.security.auth.Subject;
  -import javax.security.auth.callback.CallbackHandler;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.spi.LoginModule;
   
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.plugins.AbstractServerLoginModule;
  +/** This module has been renamed to org.jboss.security.auth.spi.IdentityLoginModule.
   
  -/** A simple login module that simply associates the principal specified
  -in the module options with any subject authenticated against the module.
  -The type of Principal class used is org.jboss.security.SimplePrincipal.
  -If no principal option is specified a principal with the name of 'guest'
  -is used.
  +@deprecated See {@link org.jboss.security.auth.spi.IdentityLoginModule} which
  +has replaced this module.
   
  -@see org.jboss.security.SimpleGroup
  -@see org.jboss.security.SimplePrincipal
  -
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.3 $
  +@version $Revision: 1.4 $
   */
  -public class IdentityLoginModule extends AbstractServerLoginModule
  +public class IdentityLoginModule
  +   extends org.jboss.security.auth.spi.IdentityLoginModule
   {
  -    private String principalName;
  -    private String roleNames;
  -
  -    /** Creates new IdentityLoginModule */
  -    public IdentityLoginModule()
  -    {
  -    }
  -   
  -    public void initialize(Subject subject, CallbackHandler handler, Map 
sharedState, Map options)
  -    {
  -        super.initialize(subject, handler, sharedState, options);
  -        principalName = (String) options.get("principal");
  -        if( principalName == null )
  -            principalName = "guest";
  -        roleNames = (String) options.get("roles");
  -    }
  -
  -    public boolean login() throws LoginException
  -    {
  -        if( super.login() == true )
  -            return true;
  -
  -        Principal principal = new SimplePrincipal(principalName);
  -        subject.getPrincipals().add(principal);
  -        // Put the principal into the sharedState map
  -        sharedState.put("javax.security.auth.login.name", principal);
  -        return true;
  -    }
  -
  -    protected Principal getIdentity()
  -    {
  -        Principal principal = new SimplePrincipal(principalName);
  -        return principal;
  -    }
  -    protected Group[] getRoleSets() throws LoginException
  -    {
  -        SimpleGroup roles = new SimpleGroup("Roles");
  -        Group[] roleSets = {roles};
  -        if( roleNames != null )
  -        {
  -            StringTokenizer tokenizer = new StringTokenizer(roleNames, ",");
  -            while( tokenizer.hasMoreTokens() )
  -            {
  -                String roleName = tokenizer.nextToken();
  -                roles.addMember(new SimplePrincipal(roleName));
  -            }
  -        }
  -        return roleSets;
  -    }
   }
  
  
  
  1.4       +4 -179    
jbosssx/src/main/org/jboss/security/plugins/samples/JaasServerLoginModule.java
  
  Index: JaasServerLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/JaasServerLoginModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JaasServerLoginModule.java        2001/03/29 02:27:12     1.3
  +++ JaasServerLoginModule.java        2001/04/11 02:04:21     1.4
  @@ -4,192 +4,17 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  -
   package org.jboss.security.plugins.samples;
  -
  -import java.util.*;
  -import java.io.*;
  -
  -import java.security.acl.Group;
  -import javax.security.auth.Subject;
  -import javax.security.auth.callback.Callback;
  -import javax.security.auth.callback.CallbackHandler;
  -import javax.security.auth.callback.NameCallback;
  -import javax.security.auth.callback.PasswordCallback;
  -import javax.security.auth.callback.UnsupportedCallbackException;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.login.FailedLoginException;
  -import javax.security.auth.spi.LoginModule;
  -
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.plugins.AbstractServerLoginModule;
   
  -/** A simple properties file based login module that consults two Java Properties
  -formatted text files for username to password("users.properties") and
  -username to roles("roles.properties") mapping. The properties files are loaded
  -during initialization using the thread context class loader. This means that
  -these files can be placed into the J2EE deployment jar or the JBoss config
  -directory.
  +import org.jboss.security.auth.spi.UsersRolesLoginModule;
   
  -The users.properties file uses a format:
  -    username1=password1
  -    username2=password2
  -    ...
  +/** This module has been renamed to 
org.jboss.security.auth.spi.UsersRolesLoginModule.
   
  -to define all valid usernames and their corresponding passwords.
  +@deprecated See {@link org.jboss.security.auth.spi.UsersRolesLoginModule 
UsersRolesLoginModule } which has replaced this module.
   
  -The roles.properties file uses a format:
  -    username1=role1,role2,...
  -    username1.RoleGroup1=role3,role4,...
  -    username2=role1,role3,...
  -
  -to define the sets of roles for valid usernames. The "username.XXX" form of
  -property name is used to assign the username roles to a particular named
  -group of roles where the XXX portion of the property name is the group name.
  -The "username=..." form is an abbreviation for "username.Roles=...".
  -The following are therefore equivalent:
  -    jduke=TheDuke,AnimatedCharacter
  -    jduke.Roles=TheDuke,AnimatedCharacter
  -
   @author <a href="[EMAIL PROTECTED]">Edward Kenworthy</a>, 12th Dec 
2000
   @author [EMAIL PROTECTED]
   */
  -public class JaasServerLoginModule extends UsernamePasswordLoginModule
  +public class JaasServerLoginModule extends UsersRolesLoginModule
   {
  -  // users+passwords, users+roles
  -    private Properties _users;   // You might think these should be static. The 
only problem with
  -    private Properties _roles;   // static attributes is they are shared across the 
VM. So I chose safety
  -                                 // over performance.
  -
  -    /**
  -     * Initialize this LoginModule.
  -     */
  -    public void initialize(Subject subject, CallbackHandler callbackHandler, Map 
sharedState, Map options)
  -    {
  -        super.initialize(subject, callbackHandler, sharedState, options);
  -        try
  -        {
  -// Load the properties file that contains the list of users and passwords
  -          LoadUsers();
  -          LoadRoles();
  -        }
  -        catch (Exception e)
  -        {
  -          System.out.print("[JAASSecurity] PANIC! Couldn't load 
users/passwords/role files.\n");
  -          e.printStackTrace();
  -// Note that although this exception isn't passed on, _users or _roles will be null
  -// so that any call to login will throw a LoginException.
  -        }
  -    }
  -
  -    /**
  -     * Method to authenticate a Subject (phase 1).
  -     *
  -     * Most of the changes from the original SimpleServerLoginModule
  -     * are made in this method. They are:
  -     * users and passwords read from users.properties file
  -     * users and roles read from roles.properties file
  -     *
  -     * I've also removed the notion of a guest login. If you want to provide 'guest'
  -     * access to your beans then simply disable security on them.
  -     *
  -     */
  -    public boolean login() throws LoginException
  -    {
  -        if (_users == null || _roles == null)
  -        {
  -          throw new LoginException("Missing _users or _roles properties file.");
  -        }
  -
  -        return super.login();
  -    }
  -
  -    /** Create the set of roles the user belongs to by parsing the roles.properties
  -        data for username=role1,role2,... and username.XXX=role1,role2,...
  -        patterns.
  -    @return Group[] containing the sets of roles 
  -    */
  -    protected Group[] getRoleSets() throws LoginException
  -    {
  -        Enumeration users = _roles.propertyNames();
  -        SimpleGroup rolesGroup = new SimpleGroup("Roles");
  -        ArrayList groups = new ArrayList();
  -        groups.add(rolesGroup);
  -        while( users.hasMoreElements() )
  -        {
  -            String user = (String) users.nextElement();
  -            String value = _roles.getProperty(user);
  -            // Check for username.RoleGroup pattern
  -            int index = user.indexOf('.');
  -            if( index > 0 )
  -            {
  -                String groupName = user.substring(index+1);
  -                if( groupName.equals("Roles") )
  -                    parseGroupMembers(rolesGroup, value);
  -                else
  -                {
  -                    SimpleGroup group = new SimpleGroup(groupName);
  -                    parseGroupMembers(rolesGroup, value);
  -                    groups.add(group);
  -                }
  -            }
  -            else
  -            {
  -                // Place these roles into the Default "Roles" group
  -                parseGroupMembers(rolesGroup, value);
  -            }
  -        }
  -        Group[] roleSets = new Group[groups.size()];
  -        groups.toArray(roleSets);
  -        return roleSets;
  -    }
  -    protected String getUsersPassword()
  -    {
  -        return _users.getProperty(getUsername(), null);
  -    }
  -
  -// utility methods
  -    private void parseGroupMembers(Group group, String value)
  -    {
  -        StringTokenizer tokenizer = new StringTokenizer(value, ",");
  -        while( tokenizer.hasMoreTokens() )
  -        {
  -            String token = tokenizer.nextToken();
  -            SimplePrincipal p = new SimplePrincipal(token);
  -            group.addMember(p);
  -        }
  -    }
  -
  -    private void LoadUsers() throws IOException
  -    {
  -      _users = LoadProperties("users.properties");
  -    }
  -
  -    private void LoadRoles() throws IOException
  -    {
  -      _roles = LoadProperties("roles.properties");
  -    }
  -
  -    /**
  -    * Loads the given properties file and returns a Properties object containing the
  -    * key,value pairs in that file.
  -    * The properties files should be in the class path.
  -    */
  -    private Properties LoadProperties(String propertiesName) throws IOException
  -    {
  -      Properties bundle = null;
  -      InputStream is 
=Thread.currentThread().getContextClassLoader().getResource(propertiesName).openStream();
  -
  -      if (null != is)
  -      {
  -         bundle = new Properties();
  -         bundle.load(is);
  -      }
  -      else
  -      {
  -         throw new IOException("Properties file " + propertiesName + " not found");
  -      }
  -      return bundle;
  -    }
   }
  
  
  
  1.4       +5 -244    
jbosssx/src/main/org/jboss/security/plugins/samples/LdapLoginModule.java
  
  Index: LdapLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/LdapLoginModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LdapLoginModule.java      2001/04/04 21:46:03     1.3
  +++ LdapLoginModule.java      2001/04/11 02:04:21     1.4
  @@ -6,253 +6,14 @@
    */
   package org.jboss.security.plugins.samples;
   
  -import java.security.Principal;
  -import java.security.acl.Group;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Map.Entry;
  -import java.util.Properties;
  -import javax.naming.Context;
  -import javax.naming.NamingEnumeration;
  -import javax.naming.NamingException;
  -import javax.naming.directory.Attribute;
  -import javax.naming.directory.Attributes;
  -import javax.naming.directory.BasicAttributes;
  -import javax.naming.directory.SearchResult;
  -import javax.naming.ldap.InitialLdapContext;
  -import javax.security.auth.Subject;
  -import javax.security.auth.callback.Callback;
  -import javax.security.auth.callback.CallbackHandler;
  -import javax.security.auth.callback.NameCallback;
  -import javax.security.auth.callback.PasswordCallback;
  -import javax.security.auth.callback.UnsupportedCallbackException;
  -import javax.security.auth.login.FailedLoginException;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.spi.LoginModule;
  +/** This module has been renamed to org.jboss.security.auth.spi.LdapLoginModule.
   
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.auth.ObjectCallback;
  -import org.jboss.security.plugins.AbstractServerLoginModule;
  +@deprecated See {@link org.jboss.security.auth.spi.LdapLoginModule}
  +which has replaced this module.
   
  -/** An implementation of LoginModule that authenticates against an LDAP server
  -using JNDI based on the configuration properties.
  -
  -The LoginModule options include whatever options your LDAP JNDI provider
  -support. Examples of standard property names are:
  -Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
  -Context.SECURITY_PROTOCOL = "java.naming.security.protocol"
  -Context.PROVIDER_URL = "java.naming.provider.url"
  -Context.SECURITY_AUTHENTICATION = "java.naming.security.authentication"
  -
  -The Context.SECURITY_PRINCIPAL is set to the distinguished name of the user
  -as obtained by the callback handler and the Context.SECURITY_CREDENTIALS
  -property is either set to the String password or Object credential depending
  -on the useObjectCredential option.
  -
  -Additional module properties include:
  -principalDNPrefix, principalDNSuffix : A prefix and suffix to add to the
  -    username when forming the user distiguished name. This is useful if you
  -    prompt a user for a username and you don't want them to have to enter the
  -    fully distinguished name. Using this property and principalDNSuffix the
  -    userDN will be formed as:
  -<code>String userDN = principalDNPrefix + username + principalDNSuffix;</code>
  -
  -useObjectCredential : indicates that the credential should be obtained as
  -an opaque Object using the org.jboss.security.plugins.ObjectCallback type
  -of Callback rather than as a char[] password using a JAAS PasswordCallback.
  -
  -rolesCtxDN : The distinguished name to the context to search for user roles.
  -roleAttributeName : The name of the attribute that contains the user roles
  -uidAttributeName : The name of the attribute that in the object containing
  - the user roles that corresponds to the userid. This is used to locate the
  - user roles.
  -
  -A sample login config:
  - testLdap {
  -    org.jboss.security.plugins.samples.LdapLoginModule required
  -        java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
  -        principalDNPrefix=uid=
  -        uidAttributeID=userid
  -        roleAttributeID=rolenames
  -        principalDNSuffix=,ou=People,o=displayscape.com
  -        rolesCtxDN=ou=Users,cn=Project1,ou=Projects,o=displayscape.com
  -        java.naming.provider.url=ldap://siren-int/
  -        java.naming.security.authentication=simple
  - };
  -
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.3 $
  +@version $Revision: 1.4 $
   */
  -public class LdapLoginModule extends AbstractServerLoginModule
  +public class LdapLoginModule extends org.jboss.security.auth.spi.LdapLoginModule
   {
  -    private static final String USE_OBJECT_CREDENTIAL_OPT = "useObjectCredential";
  -    private static final String PRINCIPAL_DN_PREFIX_OPT = "principalDNPrefix";
  -    private static final String PRINCIPAL_DN_SUFFIX_OPT = "principalDNSuffix";
  -    private static final String ROLES_CTX_DN_OPT = "rolesCtxDN";
  -    private static final String UID_ATTRIBUTE_ID_OPT = "uidAttributeID";
  -    private static final String ROLE_ATTRIBUTE_ID_OPT = "roleAttributeID";
  -
  -    public LdapLoginModule()
  -    {
  -    }
  -
  -     private transient String username;
  -     private transient Object credential;
  -    private transient SimpleGroup userRoles = new SimpleGroup("Roles");
  -
  -     public boolean login() throws javax.security.auth.login.LoginException
  -     {
  -             System.out.println("LdapLoginModule.login");
  -             if( super.login() == true )
  -        {
  -            // Use the shared username and password
  -            Object identity = sharedState.get("javax.security.auth.login.name");
  -            credential = sharedState.get("javax.security.auth.login.password");
  -            username = identity.toString();
  -        }
  -        else
  -        {
  -            // Use the callbackHander to get username and password
  -            getUsernamePassword();
  -        }
  -
  -             // Validate the user & password by creating an LDAP initial context.
  -             try
  -             {
  -                     createLdapInitContext();
  -             }
  -             catch(NamingException e)
  -             {
  -                     throw new FailedLoginException(e.toString(true));
  -             }
  -             catch(Throwable t)
  -             {
  -                     throw new FailedLoginException("Unexpected failure: 
"+t.getMessage());
  -             }
  -             return true;
  -     }
  -     
  -    protected Principal getIdentity()
  -    {
  -        return new SimplePrincipal(username);
  -    }
  -    protected Group[] getRoleSets() throws LoginException
  -    {
  -        Group[] roleSets = {userRoles};
  -        return roleSets;
  -    }
  -
  -    private void getUsernamePassword() throws LoginException
  -    {
  -        if( callbackHandler == null )
  -                     throw new LoginException("Error: no CallbackHandler 
available");
  -
  -             NameCallback ncallback = new NameCallback("LdapLoginModule username: 
");
  -             PasswordCallback pcallback = new PasswordCallback("LdapLoginModule 
password: ", false);
  -        ObjectCallback ocallback = new ObjectCallback("LdapLoginModule credential: 
");
  -             try
  -             {
  -            Object useObjectCred = options.get(USE_OBJECT_CREDENTIAL_OPT);
  -            if( useObjectCred == null || 
Boolean.valueOf(useObjectCred.toString()).booleanValue() == false )
  -            {
  -                Callback[] callbacks = {ncallback, pcallback};
  -                callbackHandler.handle(callbacks);
  -                char[] tmpPassword = pcallback.getPassword();
  -                credential = new String(tmpPassword);
  -                pcallback.clearPassword();
  -            }
  -            else
  -            {
  -                Callback[] callbacks = {ncallback, ocallback};
  -                callbackHandler.handle(callbacks);
  -                credential = ocallback.getCredential();
  -            }
  -                     username = ncallback.getName();
  -             }
  -             catch(java.io.IOException ioe)
  -             {
  -                     throw new LoginException(ioe.toString());
  -             }
  -             catch(UnsupportedCallbackException uce)
  -             {
  -                     throw new LoginException("Error: " + 
uce.getCallback().toString());
  -             }
  -    }
  -
  -     private void createLdapInitContext() throws NamingException
  -     {
  -             Properties env = new Properties();
  -        // Map all option into the JNDI InitialLdapContext env
  -        Iterator iter = options.entrySet().iterator();
  -        while( iter.hasNext() )
  -        {
  -            Entry entry = (Entry) iter.next();
  -            env.put(entry.getKey(), entry.getValue());
  -        }
  -
  -        // Set defaults for key values if they are missing
  -             String factoryName = env.getProperty(Context.INITIAL_CONTEXT_FACTORY);
  -             if( factoryName == null )
  -        {
  -                     factoryName = "com.sun.jndi.ldap.LdapCtxFactory";
  -            env.setProperty(Context.INITIAL_CONTEXT_FACTORY, factoryName);
  -        }
  -        String authType = env.getProperty(Context.SECURITY_AUTHENTICATION);
  -        if( authType == null )
  -            env.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
  -             String protocol = env.getProperty(Context.SECURITY_PROTOCOL);
  -             String providerURL = (String) options.get(Context.PROVIDER_URL);
  -             if( providerURL == null )
  -                     providerURL = "ldap://localhost:" + ((protocol != null && 
protocol.equals("ssl")) ? "389" : "636");
  -             String principalDNPrefix = (String) 
options.get(PRINCIPAL_DN_PREFIX_OPT);
  -             if( principalDNPrefix == null )
  -                     principalDNPrefix="";
  -             String principalDNSuffix = (String) 
options.get(PRINCIPAL_DN_SUFFIX_OPT);
  -             if( principalDNSuffix == null )
  -                     principalDNSuffix="";
  -             String userDN = principalDNPrefix + username + principalDNSuffix;
  -             env.setProperty(Context.PROVIDER_URL, providerURL);
  -             env.setProperty(Context.SECURITY_PRINCIPAL, userDN);
  -             env.put(Context.SECURITY_CREDENTIALS, credential);
  -             System.out.println("Logging into LDAP server, env="+env);
  -             InitialLdapContext ctx = new InitialLdapContext(env, null);
  -             System.out.println("Logged into LDAP server, "+ctx);
  -        // Query the user's roles...
  -        String rolesCtxDN = (String) options.get(ROLES_CTX_DN_OPT);
  -        if( rolesCtxDN != null )
  -        {
  -            String uidAttrName = (String) options.get(UID_ATTRIBUTE_ID_OPT);
  -            if( uidAttrName == null )
  -                uidAttrName = "uid";
  -            String roleAttrName = (String) options.get(ROLE_ATTRIBUTE_ID_OPT);
  -            if( roleAttrName == null )
  -                roleAttrName = "roles";
  -            BasicAttributes matchAttrs = new BasicAttributes(true); 
  -            matchAttrs.put(uidAttrName, username);
  -            String[] roleAttr = {roleAttrName};
  -            try
  -            {
  -                NamingEnumeration answer = ctx.search(rolesCtxDN, matchAttrs, 
roleAttr);
  -                while( answer.hasMore() )
  -                {
  -                    SearchResult sr = (SearchResult) answer.next();
  -                    Attributes attrs = sr.getAttributes();
  -                    Attribute roles = attrs.get(roleAttrName);
  -                    for(int r = 0; r < roles.size(); r ++)
  -                    {
  -                        Object value = roles.get(r);
  -                        String roleName = value.toString();
  -                        userRoles.addMember(new SimplePrincipal(roleName));
  -                    }
  -                }
  -            }
  -            catch(NamingException e)
  -            {
  -            }
  -        }
  -        // Close the context to release the connection
  -             ctx.close();
  -     }
   }
  
  
  
  1.4       +2 -2      
jbosssx/src/main/org/jboss/security/plugins/samples/RolesLoginModule.java
  
  Index: RolesLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/RolesLoginModule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RolesLoginModule.java     2001/03/29 02:27:12     1.3
  +++ RolesLoginModule.java     2001/04/11 02:04:21     1.4
  @@ -33,10 +33,10 @@
   a module that does the authentication and passes the username via
   the sharedMap as the javax.security.auth.login.name property.
   
  -@deprecated See the JaasServerLoginModule which has incorporated this behavior.
  +@deprecated See {@link org.jboss.security.auth.spi.UsersRolesLoginModule 
UsersRolesLoginModule } which has incorporated this behavior.
   
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.3 $
  +@version $Revision: 1.4 $
   */
   public class RolesLoginModule implements LoginModule
   {
  
  
  
  1.3       +6 -71     
jbosssx/src/main/org/jboss/security/plugins/samples/SimpleServerLoginModule.java
  
  Index: SimpleServerLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/SimpleServerLoginModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleServerLoginModule.java      2001/03/29 02:27:13     1.2
  +++ SimpleServerLoginModule.java      2001/04/11 02:04:21     1.3
  @@ -6,81 +6,16 @@
    */
   package org.jboss.security.plugins.samples;
   
  -import java.security.Principal;
  -import java.security.acl.Group;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.spi.LoginModule;
  +/** This module has been renamed to 
org.jboss.security.auth.spi.SimpleServerLoginModule.
   
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.plugins.samples.UsernamePasswordLoginModule;
  +@deprecated See {@link org.jboss.security.auth.spi.SimpleServerLoginModule}
  +which has replaced this module.
   
  -/** A simple server login module useful to quick setup of security for testing
  -purposes. It implements the following simple algorithm:
  -    - if password is null, authenticate the user and assign an identity of guest
  -        and a role of "guest".
  -    - else if password is equal to the user name, assign an identity equal to
  -        the username and both "user" and "guest" roles
  -    - else authentication fails.
  -
   @author <a href="[EMAIL PROTECTED]">Oleg Nitz</a>
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  +@version $Revision: 1.3 $
   */
  -public class SimpleServerLoginModule extends UsernamePasswordLoginModule
  +public class SimpleServerLoginModule
  +    extends org.jboss.security.auth.spi.SimpleServerLoginModule
   {
  -    private SimplePrincipal user;
  -    private boolean guestOnly;
  -
  -    protected Principal getIdentity()
  -    {
  -        Principal principal = user;
  -        if( principal == null )
  -            principal = super.getIdentity();
  -        return principal;
  -    }
  -
  -    protected boolean validatePassword(String inputPassword, String 
expectedPassword)
  -    {
  -        boolean isValid = false;
  -        if( inputPassword == null )
  -        {
  -            guestOnly = true;
  -            isValid = true;
  -            user = new SimplePrincipal("guest");
  -        }
  -        else
  -        {
  -            isValid = inputPassword.equals(expectedPassword);
  -        }
  -        return isValid;
  -    }
  -
  -    /** Overriden by subclasses to return the Groups that correspond to the
  -     * to the role sets assigned to the user. Subclasses should create at
  -     * least a Group named "Roles" that contains the roles assigned to the user.
  -     * A second common group is "CallerPrincipal" that provides the application
  -     * identity of the user rather than the security domain identity.
  -     * @return Group[] containing the sets of roles 
  -     */
  -    protected Group[] getRoleSets() throws LoginException
  -    {
  -        Group[] roleSets = {new SimpleGroup("Roles")};
  -        if( guestOnly == false )
  -            roleSets[0].addMember(new SimplePrincipal("user"));
  -        roleSets[0].addMember(new SimplePrincipal("guest"));
  -        return roleSets;
  -    }
  -
  -    /** Get the expected password for the current username available via
  -     * the getUsername() method. This is called from within the login()
  -     * method after the CallbackHandler has returned the username and
  -     * candidate password.
  -     * @return the value of getUsername()
  -     */
  -    protected String getUsersPassword() throws LoginException
  -    {
  -        return getUsername();
  -    }
  -
   }
  
  
  
  1.2       +5 -163    
jbosssx/src/main/org/jboss/security/plugins/samples/UsernamePasswordLoginModule.java
  
  Index: UsernamePasswordLoginModule.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosssx/src/main/org/jboss/security/plugins/samples/UsernamePasswordLoginModule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UsernamePasswordLoginModule.java  2001/03/29 02:27:13     1.1
  +++ UsernamePasswordLoginModule.java  2001/04/11 02:04:21     1.2
  @@ -6,173 +6,15 @@
    */
   package org.jboss.security.plugins.samples;
   
  -import java.io.IOException;
  -import java.util.ArrayList;
  -import java.util.Enumeration;
  -import java.security.Principal;
  -import java.security.acl.Group;
  -import javax.security.auth.Subject;
  -import javax.security.auth.callback.Callback;
  -import javax.security.auth.callback.CallbackHandler;
  -import javax.security.auth.callback.NameCallback;
  -import javax.security.auth.callback.PasswordCallback;
  -import javax.security.auth.callback.UnsupportedCallbackException;
  -import javax.security.auth.login.LoginException;
  -import javax.security.auth.login.FailedLoginException;
  -import javax.security.auth.spi.LoginModule;
  +/** This module has been renamed to 
org.jboss.security.auth.spi.UsernamePasswordLoginModule.
   
  -import org.jboss.security.SimpleGroup;
  -import org.jboss.security.SimplePrincipal;
  -import org.jboss.security.plugins.AbstractServerLoginModule;
  +@deprecated See {@link org.jboss.security.auth.spi.UsernamePasswordLoginModule}
  +which has replaced this module.
   
  -
  -/** An abstract subclass of AbstractServerLoginModule that imposes a
  -an identity == String username, credentials == String password view on
  -the login process. Subclasses override the getUsersPassword()
  -and getUsersRoles() methods to return the expected password and roles
  -for the user.
  -
  -@see #getUsername()
  -@see #getUsersPassword()
  -@see #getUsersRoles()
  -
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@version $Revision: 1.2 $
   */
  -public abstract class UsernamePasswordLoginModule extends AbstractServerLoginModule
  +public abstract class UsernamePasswordLoginModule
  +    extends org.jboss.security.auth.spi.UsernamePasswordLoginModule
   {
  -    /** The login identity */
  -    private Principal identity;
  -    /** The proof of login identity */
  -    private char[] credential;
  -
  -    /**
  -     */
  -    public boolean login() throws LoginException
  -    {
  -        // See if shared credentials exist
  -        if( super.login() == true )
  -        {
  -            // Setup our view of the user
  -            Object username = sharedState.get("javax.security.auth.login.name");
  -            if( username instanceof Principal )
  -                identity = (Principal) username;
  -            else
  -            {
  -                String name = username.toString();
  -                identity = new SimplePrincipal(name);
  -            }
  -            Object password = sharedState.get("javax.security.auth.login.password");
  -            if( password instanceof char[] )
  -                credential = (char[]) password;
  -            else
  -            {
  -                String tmp = password.toString();
  -                credential = tmp.toCharArray();
  -            }
  -            return true;
  -        }
  -
  -        String[] info = getUsernameAndPassword();
  -        String username = info[0];
  -        String password = info[1];
  -        identity = new SimplePrincipal(username);
  -
  -        // Validate the password supplied by the subclass
  -        String expectedPassword = getUsersPassword();
  -        if( validatePassword(password, expectedPassword) == false )
  -        {
  -            System.out.println("[JAASSecurity] Bad password.");
  -            throw new FailedLoginException("Password Incorrect/Password Required");
  -        }
  -        System.out.print("[JAASSecurity] User '" + username + "' authenticated.\n");
  -
  -        if( getUseFirstPass() == true )
  -        {    // Add the username and password to the shared state map
  -             sharedState.put("javax.security.auth.login.name", identity);
  -             sharedState.put("javax.security.auth.login.password", credential);
  -        }
  -        return true;
  -    }
  -
  -    protected Principal getIdentity()
  -    {
  -        return identity;
  -    }
  -
  -    protected Object getCredentials()
  -    {
  -        return credential;
  -    }
  -    protected String getUsername()
  -    {
  -        return getIdentity().getName();
  -    }
  -
  -    /** Called by login() to acquire the username and password strings for
  -        authentication. This method does no validation of either.
  -    @return String[], [0] = username, [1] = password
  -    @exception LoginException thrown if CallbackHandler is not set or fails.
  -    */
  -    protected String[] getUsernameAndPassword() throws LoginException
  -    {
  -        String[] info = {null, null};
  -        // prompt for a username and password
  -        if( callbackHandler == null )
  -        {
  -            throw new LoginException("Error: no CallbackHandler available " +
  -                                 "to garner authentication information from the 
user");
  -        }
  -        NameCallback nc = new NameCallback("User name: ", "guest");
  -        PasswordCallback pc = new PasswordCallback("Password: ", false);
  -        Callback[] callbacks = {nc, pc};
  -        String username = null;
  -        String password = null;
  -        try
  -        {
  -            callbackHandler.handle(callbacks);
  -            username = nc.getName();
  -            char[] tmpPassword = pc.getPassword();
  -            if( tmpPassword != null )
  -            {
  -                credential = new char[tmpPassword.length];
  -                System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length);
  -                pc.clearPassword();
  -            }
  -            password = new String(credential);
  -        }
  -        catch(java.io.IOException ioe)
  -        {
  -            throw new LoginException(ioe.toString());
  -        }
  -        catch(UnsupportedCallbackException uce)
  -        {
  -            throw new LoginException("CallbackHandler does not support: " + 
uce.getCallback());
  -        }
  -        info[0] = username;
  -        info[1] = password;
  -        return info;
  -    }
  -
  -    /** A hook that allows subclasses to change the validation of the input
  -        password against the expected password. This version checks that
  -        neither inputPassword or expectedPassword are null that that
  -        inputPassword.equals(expectedPassword) is true;
  -    @return true if the inputPassword is valid, false otherwise.
  -    */
  -    protected boolean validatePassword(String inputPassword, String 
expectedPassword)
  -    {
  -        if( inputPassword == null || expectedPassword == null )
  -            return false;
  -        return inputPassword.equals(expectedPassword);
  -    }
  -
  -    /** Get the expected password for the current username available via
  -        the getUsername() method. This is called from within the login()
  -        method after the CallbackHandler has returned the username and
  -        candidate password.
  -    @return the valid password String
  -    */
  -    abstract protected String getUsersPassword() throws LoginException;
  -
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to