Hi all; i'm using JBoss 3.2.6 on Windows XP sp 2 and SDK 1.4.2_07; i have 
created a my .ear and i have created a my security-domain; well i have modified 
the auth.conf file by adding:

eng {
  |    // jBoss LoginModule
  |    org.jboss.security.ClientLoginModule  required;
  | 
  |    // Put your login modules that need jBoss here
  | };

Then i have modifed the login-config.xml in this way:

                                              <authentication>            
<login-module code = "org.jboss.security.auth.spi.ProxyLoginModule"
  |              flag = "required">        <module-option name = "moduleName">  
                                            </module-option>        
<module-option name = "unauthenticatedIdentity">      </module-option>          
     <module-option name = "dsJndiName">               </module-option>         
      <module-option name = "daemonUsername">      </module-option>             
  <module-option name = "daemonPassword">            </module-option>           
 </login-module>         </authentication>      </application-policy>           
                                                                                
                                <security-domain>              
</security-domain>                                                              
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
   <= 3.2.5 passes login principal
  |                 ps = con.prepareStatement
  |                     ("SELECT PASSWORD FROM STAFFMEMBER WHERE MEMBERID = ?");
  |                 ps.setString(1, un);
  |             }
  |             rs = ps.executeQuery();
  |             if(rs.next()) {
  |                 return rs.getString(1).equals (inputPassword);
  |             }
  |                  } catch(NamingException ex) {
  |             ex.printStackTrace();
  |                  } catch(SQLException ex) {
  |             ex.printStackTrace();
  |                  } finally {
  |             try {
  |                 closeAll (rs, ps, con);
  |             } catch (SQLException ex) {
  |                 ex.printStackTrace();
  |             }
  |                  }
  |                  return false;
  |          */
  |         return true;
  |     }
  | 
  |     protected Group[] getRoleSets() throws LoginException {
  |         log.info( "getting rolesets" );
  |         if (getUnauthenticatedIdentity() != null
  |             && getIdentity().equals(getUnauthenticatedIdentity())) {
  |             Group[] grps = new Group[0];
  |             return grps;
  |         }
  |         if (daemonUsername != null && getUsername().equals(daemonUsername)) 
{
  |             // Create Caller Principal
  |             SimpleGroup princip = new SimpleGroup("CallerPrincipal");
  |             princip.addMember
  |                     (new SimplePrincipal("StaffManagementMember_Daemon"));
  |             // create roles, start with default role
  |             Group roles = new SimpleGroup("Roles");
  |             SimplePrincipal p = new SimplePrincipal("StaffManagementUser");
  |             roles.addMember(p);
  |             p = new SimplePrincipal("StaffManagementRole_Daemon");
  |             roles.addMember(p);
  |             Group[] grps = new Group[] {princip, roles};
  |             return grps;
  |         }
  |         List groups = new ArrayList();
  |         // gather information
  |         Connection con = null;
  |         try {
  |             // prepare db connection
  |             InitialContext ctx = new InitialContext();
  |             DataSource ds = (DataSource) ctx.lookup(dsJndiName);
  |             con = ds.getConnection();
  |             // Create Caller Principal
  |             long memberDBId = addCallerPrincipal(con, groups);
  |             // create roles, start with default role
  |             SimpleGroup rolesGroup = new SimpleGroup("Roles");
  |             groups.add(rolesGroup);
  |             SimplePrincipal p = new SimplePrincipal("StaffManagementUser");
  |             rolesGroup.addMember(p);
  |             // add roles from db
  |             addGroupsAsRoles(con, rolesGroup, memberDBId, true);
  |         } catch (NamingException ex) {
  |             throw new LoginException(ex.toString(true));
  |         } catch (SQLException ex) {
  |             ex.printStackTrace();
  |             throw new LoginException(ex.toString());
  |         } finally {
  |             try {
  |                 closeAll(null, null, con);
  |             } catch (SQLException ex) {
  |                 ex.printStackTrace();
  |                 throw new LoginException(ex.toString());
  |             }
  |         }
  | 
  |         Group[] roleSets = new Group[groups.size()];
  |         groups.toArray(roleSets);
  |         for( int i = 0; i < roleSets.length; i++ ){
  | 
  |             log.info( "Eleemnto:"+i+" "+roleSets );
  |         }
  |         return roleSets;
  |     }
  | 
  |     private long addCallerPrincipal(Connection con, List groups) throws
  |             SQLException, LoginException {
  |         /*
  |             PreparedStatement ps = null;
  |             ResultSet rs = null;
  |             long dbid = 0;
  |             try {
  |                 String un = getUsername();
  |                 if (un.startsWith ("StaffManagementMember_")) {
  |                     // JBoss 3.2.6 passes EJB container principal
  |                     return Long.parseLong (un.substring(22));
  |                 }
  |                 // JBoss <= 3.2.5 passes login principal
  |                 ps = con.prepareStatement
  |                     ("SELECT DBID FROM STAFFMEMBER WHERE MEMBERID = ?");
  |                 ps.setString(1, un);
  |                 rs = ps.executeQuery();
  |                 if(! rs.next()) {
  |                     throw new LoginException
  |                         ("Authenticated user vanished from table");
  |                 }
  |                 dbid = rs.getLong(1);
  |                 SimpleGroup rolesGroup = new SimpleGroup("CallerPrincipal");
  |                 groups.add(rolesGroup);
  |                 rolesGroup.addMember
  |                     (new SimplePrincipal
  |                      ("StaffManagementMember_" + dbid));
  |             } finally {
  |                 closeAll (rs, ps, null);
  |             }
  |             return dbid;
  |          */
  |         log.info( "Ritorno 0" );
  |         return 0L;
  |     }
  | 
  |     private void addGroupsAsRoles(Connection con, SimpleGroup roles,
  |                                   long id, boolean isMember) throws
  |             SQLException, LoginException {
  |         /*
  |             PreparedStatement ps = null;
  |             ResultSet rs = null;
  |             try {
  |                 String type = "M";
  |                 if (!isMember) {
  |                     type = "G";
  |                 }
  |                 ps = con.prepareStatement
  |                     ("SELECT GROUPID FROM STAFFMAP "
  |                      + "WHERE CONTAINED = ? AND TYPE = ?");
  |                 ps.setLong(1, id);
  |                 ps.setString(2, type);
  |                 rs = ps.executeQuery();
  |                 while(rs.next()) {
  |                     long grpId = rs.getLong(1);
  |                     if (grpId < 100) {
  |                         roles.addMember (new SimplePrincipal
  |                                          ("StaffManagementRole_" + grpId));
  |                     } else {
  |                         roles.addMember
  |                             (new SimplePrincipal (lookupGroup (con, 
grpId)));
  |                     }
  |                     addGroupsAsRoles (con, roles, grpId, false);
  |                 }
  |             } finally {
  |                 closeAll (rs, ps, null);
  |             }
  |          */
  |         log.info( "addGroupRoles" );
  |         for (int i = 0; i < 10; i++) {
  | 
  |             roles.addMember(new SimplePrincipal("StaffManagementRole_" + 
i));
  |             addGroupsAsRoles(con, roles, i, false);
  |         }
  |     }
  | 
  |     private String lookupGroup(Connection con, long grpId) throws 
SQLException,
  |             LoginException {
  |         PreparedStatement ps = null;
  |         ResultSet rs = null;
  |         try {
  |             ps = con.prepareStatement
  |                  ("SELECT NAME FROM STAFFGROUP WHERE DBID = ?");
  |             ps.setLong(1, grpId);
  |             rs = ps.executeQuery();
  |             if (!rs.next()) {
  |                 throw new LoginException
  |                         ("Group vanished from table");
  |             }
  |             return rs.getString(1);
  |         } finally {
  |             closeAll(rs, ps, null);
  |         }
  |     }
  | 
  | 
  |     private void closeAll(ResultSet rs, Statement st,
  |                           Connection con) throws SQLException {
  |         if (rs != null) {
  |             rs.close();
  |         }
  |         if (st != null) {
  |             st.close();
  |         }
  |         if (con != null) {
  |             con.close();
  |         }
  |     }
  | 
  |     protected String getUsersPassword() throws LoginException {
  |         
  |         log.info( "Returning password" );
  |         return null;
  |     }
  | }

It seems to me all well done.... can anybody help me?
As you can see this class i very simple... i have done nothing particular...
Thanks.                                                        

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3878824#3878824

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3878824


-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_idt12&alloc_id344&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to