KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > jspbeans > AceCustomerValidator


1 /*
2  * AceCustomerValidator.java
3  *
4  * Created on June 4, 2003, 12:19 PM
5  */

6
7 package com.quikj.application.web.talk.jspbeans;
8
9 import java.sql.*;
10
11 /**
12  *
13  * @author amit
14  */

15 public class AceCustomerValidator implements ContactCenterAuthenticatorInterface
16 {
17     
18     /** Holds value of property jdbcClass. */
19     private String JavaDoc jdbcClass;
20     
21     /** Holds value of property url. */
22     private String JavaDoc url;
23     
24     /** Holds value of property user. */
25     private String JavaDoc user;
26     
27     /** Holds value of property password. */
28     private String JavaDoc password;
29     
30     /** Creates a new instance of AceCustomerValidator */
31     public AceCustomerValidator()
32     {
33     }
34     
35     public String JavaDoc init()
36     {
37         if ((jdbcClass == null) || (url == null))
38         {
39             return "All required parameters have not been supplied";
40         }
41         
42         return null;
43     }
44     
45     public void setParam(String JavaDoc name, String JavaDoc value)
46     {
47         if (name.equals("jdbc") == true)
48         {
49             jdbcClass = value;
50         }
51         else if (name.equals("url") == true)
52         {
53             url = value;
54         }
55         else if (name.equals("user") == true)
56         {
57             user = value;
58         }
59         else if (name.equals("password") == true)
60         {
61             password = value;
62         }
63     }
64     
65     public CustomerInformationElement validate(String JavaDoc user, String JavaDoc password)
66     {
67         Connection c = null;
68         
69         try
70         {
71             c = getConnection();
72             if (c == null)
73             {
74                 return null;
75             }
76             
77             String JavaDoc sql = "select fullname,email,info from ace_restricted_access_user_tbl where user = ? and password = password(?)";
78             PreparedStatement ps = c.prepareStatement(sql);
79             ps.setString(1, user);
80             ps.setString(2, password);
81             ResultSet rs = ps.executeQuery();
82             
83             if (rs.next() == false)
84             {
85                 return null;
86             }
87             
88             CustomerInformationElement element = new CustomerInformationElement();
89             element.setFullName(rs.getString(1));
90             element.setEmail(rs.getString(2));
91             element.setInfo(rs.getString(3));
92             
93             c.close();
94             return element;
95         }
96         catch (Exception JavaDoc ex)
97         {
98             if (c != null)
99             {
100                 try
101                 {
102                     c.close();
103                 }
104                 catch (SQLException ex1)
105                 {
106                     ;
107                 }
108             }
109         }
110         
111         return null;
112     }
113     
114     /** Getter for property jdbcClass.
115      * @return Value of property jdbcClass.
116      *
117      */

118     public String JavaDoc getJdbcClass()
119     {
120         return this.jdbcClass;
121     }
122     
123     /** Setter for property jdbcClass.
124      * @param jdbcClass New value of property jdbcClass.
125      *
126      */

127     public void setJdbcClass(String JavaDoc jdbcClass)
128     {
129         this.jdbcClass = jdbcClass;
130     }
131     
132     /** Getter for property url.
133      * @return Value of property url.
134      *
135      */

136     public String JavaDoc getUrl()
137     {
138         return this.url;
139     }
140     
141     /** Setter for property url.
142      * @param url New value of property url.
143      *
144      */

145     public void setUrl(String JavaDoc url)
146     {
147         this.url = url;
148     }
149     
150     /** Getter for property user.
151      * @return Value of property user.
152      *
153      */

154     public String JavaDoc getUser()
155     {
156         return this.user;
157     }
158     
159     /** Setter for property user.
160      * @param user New value of property user.
161      *
162      */

163     public void setUser(String JavaDoc user)
164     {
165         this.user = user;
166     }
167     
168     /** Getter for property password.
169      * @return Value of property password.
170      *
171      */

172     public String JavaDoc getPassword()
173     {
174         return this.password;
175     }
176     
177     /** Setter for property password.
178      * @param password New value of property password.
179      *
180      */

181     public void setPassword(String JavaDoc password)
182     {
183         this.password = password;
184     }
185     
186     private Connection getConnection()
187     throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, SQLException, IllegalAccessException JavaDoc
188     {
189         Class.forName(jdbcClass).newInstance();
190         return DriverManager.getConnection(url, user, password);
191     }
192     
193 }
194
Popular Tags