[jboss-user] [EJB 3.0] - Re: unable to find LoginModule class

JPagera do-not-reply at jboss.com
Sun Oct 14 02:29:32 EDT 2007


this is my LoginModule class


  | 
  | package com.jpagera.login;
  | 
  | import java.io.IOException;
  | 
  | import java.util.Map;
  | 
  | 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.spi.LoginModule;
  | import java.sql.*;
  | 
  | import java.util.HashSet;
  | import java.util.List;
  | import java.util.Set;
  | import java.util.Vector;
  | 
  | 
  | public class JPageraLoginModule implements LoginModule {
  | 
  |     private Subject subject_;
  |     private String userName ;
  |     private char[] password;
  |     private CallbackHandler _callbackHandler_;
  |     private boolean loginResult;
  |     
  |     private String driverDB_ ;
  |     private String userDB_ ;
  |     private String passwordDB_ ;
  |     private String urlDB_ ;
  |     private Map sharedState_;
  |     private Map options_;
  |     private JPageraPrincipal _jPageraRolePricipl[] ;
  |     
  |     public JPageraLoginModule() {
  |     }
  | 
  |     public void initialize(Subject subject, CallbackHandler callbackHandler, 
  |                            Map<String, ?> sharedState, 
  |                            Map<String, ?> options) {
  |                            
  |         this.subject_ = subject;
  |         this._callbackHandler_ = callbackHandler;
  |         this.sharedState_ = sharedState;
  |         this.options_ = options;
  |         
  |     }
  | 
  |     public boolean login() throws LoginException {
  |     
  |         System.out.println("Start LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOGIN MEHTOD");
  |         if(_callbackHandler_ == null){
  |             throw new LoginException("JPageraLoginModule Exception _callbackHandler_ is null ");
  |         }
  |         
  |         Callback callbackx[] = new Callback[2];
  | 
  |         callbackx[0] = new NameCallback("Username");
  |         callbackx[1] = new PasswordCallback("Password:",false);
  | 
  |             
  |        
  |         try {
  |             _callbackHandler_.handle(callbackx);
  |             
  |             System.out.println("LOGINNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN_U "+ ((NameCallback) callbackx[0]).getName());
  |             System.out.println("LOGINNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN_P "+ ((PasswordCallback) callbackx[1]).getPassword());
  |             
  |             driverDB_ = (String)options_.get("driverDB_");
  |             userDB_ = (String)options_.get("userDB_");
  |             passwordDB_ = (String)options_.get("passwordDB_");
  |             urlDB_ = (String)options_.get("urlDB_");
  |             
  |             System.out.println("driverDB : "+driverDB_);
  |             System.out.println("userDB : "+userDB_);
  |             System.out.println("passwordDB : "+passwordDB_);
  |             System.out.println("urlDB : "+urlDB_);
  |             userName = ((NameCallback) callbackx[0]).getName();
  |             
  |             loginResult = checkUserNameAndPassword(((NameCallback) callbackx[0]).getName(),((PasswordCallback) callbackx[1]).getPassword());
  |             
  |             System.out.println("IN LOGIN METHOD FINISH....."+loginResult);
  |             return loginResult;
  |             
  |         } catch (UnsupportedCallbackException e) {
  |             // TODO
  |             throw new LoginException("JPageraLoginModule Exception UnsupportedCallbackException ");
  |         } catch (IOException e) {
  |             // TODO
  |             throw new LoginException("JPageraLoginModule Exception IOException ");
  |         }
  |     }
  | 
  |     public boolean commit() throws LoginException {
  |  
  |         /*if(!loginResult){
  |             return loginResult;
  |         }*/
  |         if (subject_.isReadOnly())
  |           {
  |             throw new LoginException("JPageraLoginModule Exception Subject is read only!");
  |           }
  |           
  |         
  |         System.out.println("NAMEEEEEEEEEEEEEEEEEEEEEEEEEEEE "+userName);
  |         JPageraPrincipal jpageraPrincipl = new JPageraPrincipal(userName);
  |         //JPageraPrincipal jpageraPrinciplAdmin = new JPageraPrincipal("ADMIN");
  |         subject_.getPrincipals().add(jpageraPrincipl);
  |         //subject_.getPrincipals().add(jpageraPrinciplAdmin);
  |         
  |         for (int i = 0; i < _jPageraRolePricipl.length; i++)  {
  |             subject_.getPrincipals().add(_jPageraRolePricipl);
  |         }
  |         
  |         System.out.println("FINISH COMMITE.................");
  |         
  |         Object[] ty = subject_.getPrincipals().toArray();
  |         for (int i = 0; i < ty.length; i++)  {
  |             System.out.println(i+" Prin ........... "+ ( (JPageraPrincipal) ty).getName());
  |         }
  |         
  |         return true;
  |     }
  | 
  |     public boolean abort() {
  |         userName = null;
  |         password = null;
  |         return true;
  |     }
  | 
  |     public boolean logout() {
  |         
  |         userName = null;
  |         password = null;
  |         subject_.getPrincipals().clear();
  |         return true;
  |     }
  |     
  |     
  |     
  | 
  |         private boolean checkUserNameAndPassword(String userName_dB , char[] passowrd_DB){
  | 
  |             
  |          Statement statem = null;
  |          ResultSet result1 = null;
  |          long userId = 0;
  |          Set<String> roleNames = new HashSet(); 
  |          Connection conn = null;
  |             try {
  |             
  |                 conn = getConnection();
  |                 statem = conn.createStatement();
  |                 
  |                 String f = " SELECT USER_ID from USERS WHERE USERS.USER_LOGINNAME LIKE '"+userName_dB+"'" +
  |                  "  AND USERS.USER_PASSWORD LIKE '"+new String(passowrd_DB) +"' " +
  |                  "  AND USERS.USRE_ACTIVE = 0 ";
  |                 
  |                 result1 = statem.executeQuery(f);
  |                 
  |                 
  |                 System.out.println("DB_NAME : "+userName_dB);
  |                 System.out.println("DB_PASSOWRD : "+new String(passowrd_DB));
  |                 System.out.println("RESULT_DB : "+result1.getMetaData().getColumnCount());
  |                if(result1.next()){
  |                  userId = result1.getLong(1);
  |                  System.out.println("NEXT : "+userId);
  |                }else{
  |                    return false;
  |                }
  |                 
  |             
  |                 ResultSet result2 = statem.executeQuery(" SELECT ROLES.ROLE_NAME FROM USERS , ROLES , USER_ROLE  " +
  |                 " WHERE  ROLES.ROLE_ID = USER_ROLE.ROLE_ID AND USER_ROLE.USER_ID = "+userId);
  | 
  |                 System.out.println(result2.getMetaData().getColumnCount());
  |                 while(result2.next()){
  |                     roleNames.add(result2.getString("ROLE_NAME"));
  |                 }
  |                 
  |                 System.out.println("SIZE "+roleNames.size());
  |                 String q4 = " SELECT ROLES.ROLE_NAME FROM ROLES , GROUP_ROLES , GROUP_USERS , GROUPS " +
  |                             " WHERE ROLES.ROLE_ID = GROUP_ROLES.ROLE_ID AND " +
  |                             " GROUP_ROLES.GROUP_ID = GROUP_USERS.GROUP_ID AND "+
  |                             " GROUP_USERS.USER_ID = "+userId+"";
  |               
  |                 
  |                  ResultSet result3 = statem.executeQuery(q4);
  |                 
  |                 while(result3.next()){
  |                     roleNames.add( result3.getString("ROLE_NAME"));
  |                 }
  |                 
  |                 Object[] obA = roleNames.toArray();
  |                 _jPageraRolePricipl = new JPageraPrincipal[obA.length];
  |                 for (int i = 0; i < obA.length; i++)  {
  |                     System.out.println("ROLE_NAME : "+(String)obA);
  |                     JPageraPrincipal currJPageraPri = new JPageraPrincipal((String)obA);
  |                     _jPageraRolePricipl = currJPageraPri;
  |                 }
  |                 System.out.println("FINISH CHECK_USER_NAME AND PASSOWRD");
  |             } catch (SQLException e) {
  |                 // TODO
  |                 System.out.println("JPageraLoginModule Exception SQLException On Connect ");
  |                 e.printStackTrace();
  |                 return false;
  |             } catch (ClassNotFoundException e) {
  |                 // TODO
  |                  System.out.println("JPageraLoginModule Exception ClassNotFoundException ");
  |                 e.printStackTrace();
  |             }
  | 
  |             try {
  |                 statem.close();
  |                 conn.close();
  |             } catch (SQLException e) {
  |                 // TODO
  |                  System.out.println("JPageraLoginModule Exception SQLException  On Close ");
  |                 e.printStackTrace();
  |                 
  |             }
  |             
  |             return true;
  |         }
  | 
  | 
  |         public  Connection getConnection() throws SQLException, 
  |                                                         ClassNotFoundException {
  |               Class.forName(driverDB_);
  |               Connection conn = DriverManager.getConnection(urlDB_,userDB_,passwordDB_);
  |               return conn;
  |           }
  | 
  |  
  | 
  |     public void setUserName(String userName) {
  |         this.userName = userName;
  |     }
  | 
  |     public String getUserName() {
  |         return userName;
  |     }
  | 
  |     public void setPassword(char[] password) {
  |         this.password = password;
  |     }
  | 
  |     public char[] getPassword() {
  |         return password;
  |     }
  |  
  | 
  |     public void setLoginResult(boolean loginResult) {
  |         this.loginResult = loginResult;
  |     }
  | 
  |     public boolean isLoginResult() {
  |         return loginResult;
  |     }
  | 
  |     public void setSubject_(Subject subject_) {
  |         this.subject_ = subject_;
  |     }
  | 
  |     public Subject getSubject_() {
  |         return subject_;
  |     }
  | 
  |     public void setCallbackHandler_(CallbackHandler callbackHandler_) {
  |         this._callbackHandler_ = callbackHandler_;
  |     }
  | 
  |     public CallbackHandler getCallbackHandler_() {
  |         return _callbackHandler_;
  |     }
  | 
  |     public void setSharedState_(Map sharedState_) {
  |         this.sharedState_ = sharedState_;
  |     }
  | 
  |     public Map getSharedState_() {
  |         return sharedState_;
  |     }
  | 
  |     public void setOptions_(Map options_) {
  |         this.options_ = options_;
  |     }
  | 
  |     public Map getOptions_() {
  |         return options_;
  |     }
  | }
  | 
  | 
  | 

...........................


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

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



More information about the jboss-user mailing list