in una web app ricevo da una form username e password . devo verificiare se questi valori appartengono ad uno user censito su oracle
la wab app accede al db tramite Spring con il seguente xml
codice:<bean id="tjtDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@//host:1521/schema" /> <property name="username" value="userV" /> <property name="password" value="passwordV" /> </bean>
il codice per verificare uno user è il seguente
codice:public boolean authenticateUser (String urlConnection , String usrName , String pwd) throws DatabaseException ,SQLException, NamingException { boolean authenticateUser = true ; Connection conn = null; Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/gipsydb"); try{ Properties connectionProps = new Properties(); connectionProps.put("user", usrName); connectionProps.put("password", pwd); conn = DriverManager.getConnection(AppConfiguration.getStringValue("dataSource"),"usrName","pwd"); //conn = dataSource.getConnection(usrName,pwd); //DatabaseMetaData dbmd=conn.getMetaData(); //dbmd.getUserName(); logger.info("CONN:"+conn); // conn.getProperties().get("password"); if(conn == null){ authenticateUser = false; } if (!conn.isValid(50000)){ authenticateUser = false; } if (conn.getAutoCommit()){ authenticateUser = false; } // if (conn.getSchema()!=null && !conn.getSchema().equals("MIJCV")){ // authenticateUser = false; // } if (conn.createStatement()==null) { authenticateUser = false; } conn.close(); } catch(Exception e) { logger.error(e.getMessage(), e); throw new DatabaseException(e.getMessage(), e); } catch(Throwable te){ logger.error(te.getMessage(), te); throw new DatabaseException(te.getMessage(), te); } return authenticateUser; }
ma non valida tutte le utenze
Grazie a chi interviene

Rispondi quotando

