KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > security > ChangePassword


1 package dinamica.security;
2
3 import dinamica.*;
4 import javax.sql.DataSource JavaDoc;
5 import java.sql.*;
6
7 /**
8  * Change current user password using Dinamica
9  * security model database structure (table s_user).
10  * <br><br>
11  * (c) 2004 Martin Cordova<br>
12  * This code is released under the LGPL license<br>
13  * Dinamica Framework - http://www.martincordova.com
14  * @author Martin Cordova (dinamica@martincordova.com)
15  * */

16 public class ChangePassword extends GenericTransaction
17 {
18
19     /* (non-Javadoc)
20      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
21      */

22     public int service(Recordset inputParams) throws Throwable JavaDoc
23     {
24         
25         int rc = 0;
26         
27         //reuse superclass code
28
super.service(inputParams);
29
30         //get security datasource
31
String JavaDoc jndiName = (String JavaDoc)getContext().getAttribute("dinamica.security.datasource");
32         if (jndiName==null)
33             throw new Throwable JavaDoc("Context attribute [dinamica.security.datasource] is null, check your security filter configuration.");
34         
35         //get datasource and DB connection
36
DataSource JavaDoc ds = Jndi.getDataSource(jndiName);
37         Connection conn = ds.getConnection();
38         this.setConnection(conn);
39
40         try
41         {
42             
43             conn.setAutoCommit(false);
44             
45             //get db channel
46
Db db = getDb();
47             
48             //get user primary key - required for password history
49
Recordset user = db.get(getSQL(getResource("getuserkey.sql"), inputParams));
50             user.next();
51             Integer JavaDoc userID = user.getInteger("user_id");
52             inputParams.setValue("userid", userID);
53             
54             //execute update query
55
db.exec(getSQL(getResource("update.sql"), inputParams));
56
57             //execute update query
58
db.exec(getSQL(getResource("insert-passlog.sql"), inputParams));
59             
60             conn.commit();
61             
62         }
63         catch (Throwable JavaDoc e)
64         {
65             if (conn!=null)
66                 conn.rollback();
67             throw e;
68         }
69         finally
70         {
71             if (conn!=null)
72                 conn.close();
73         }
74         
75         return rc;
76         
77     }
78
79 }
80
Popular Tags