diff options
| author | guest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129> | 2008-09-23 21:29:27 +0000 |
|---|---|---|
| committer | guest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129> | 2008-09-23 21:29:27 +0000 |
| commit | d6fa96b4cd67cf4fa18b5b9b6739f9bc2494a9f4 (patch) | |
| tree | 00aa9a27acb6b4c8d9868795a5295e9231f1eb20 /src/YalpAuth | |
initial import
git-svn-id: http://manut.eu/svn/yalp/trunk@1 f059d3a0-6783-47b7-97ff-1fe0bbf25129
Diffstat (limited to 'src/YalpAuth')
| -rw-r--r-- | src/YalpAuth/YalpPGSqlAuth/DatabaseDefines.java | 65 | ||||
| -rw-r--r-- | src/YalpAuth/YalpPGSqlAuth/YalpAuthInterfaceImpl.java | 137 | ||||
| -rw-r--r-- | src/YalpAuth/YalpPGSqlAuth/YalpPGSqlAuth.java | 32 |
3 files changed, 234 insertions, 0 deletions
diff --git a/src/YalpAuth/YalpPGSqlAuth/DatabaseDefines.java b/src/YalpAuth/YalpPGSqlAuth/DatabaseDefines.java new file mode 100644 index 0000000..5ff92c7 --- /dev/null +++ b/src/YalpAuth/YalpPGSqlAuth/DatabaseDefines.java @@ -0,0 +1,65 @@ +/*
+ * Copyright (c) 2006 Manuel Traut and Volker Dahnke
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors: Manuel Traut and Volker Dahnke
+ */
+package YalpAuth.YalpPGSqlAuth;
+
+/*
+ * Class DatabaseDefines
+ *
+ * <em></em>
+ *
+ * @author Manuel Traut
+ *
+ * @version 0.1 28-08-2008<br>
+ *
+ */
+
+public class DatabaseDefines {
+
+ public String dbConnection="jdbc:postgresql://10.0.3.20:5432/yalp_user";
+ public String dbUser="yalp";
+ public String dbPasswd="huhu";
+
+/*
+ * set string for dbConnection
+ * @param dbConnection
+ * "jdbc:postgresql://<serverIP>:<portOfDB>/<dataBaseName>";
+ */
+ public void setDBConnection(String dbConnection){
+ this.dbConnection = dbConnection;
+ }
+
+/*
+ * set userName for db Edit
+ * @param dbUser
+ */
+ public void setDBUser(String dbUser){
+ this.dbUser = dbUser;
+ }
+
+/*
+ * set string for db Password
+ * @param DBPasswd
+ */
+ public void setDBPasswd(String DBPasswd){
+ this.dbPasswd = DBPasswd;
+ }
+
+ public String getDBConnection(){
+ return this.dbConnection;
+ }
+
+ public String getDBUser(){
+ return this.dbUser;
+ }
+
+ public String getDBPasswd(){
+ return this.dbPasswd;
+ }
+}
diff --git a/src/YalpAuth/YalpPGSqlAuth/YalpAuthInterfaceImpl.java b/src/YalpAuth/YalpPGSqlAuth/YalpAuthInterfaceImpl.java new file mode 100644 index 0000000..b87bce3 --- /dev/null +++ b/src/YalpAuth/YalpPGSqlAuth/YalpAuthInterfaceImpl.java @@ -0,0 +1,137 @@ +package YalpAuth.YalpPGSqlAuth; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.*; +import java.sql.*; + +import YalpInterfaces.*; + +public class YalpAuthInterfaceImpl { + private String db; + private String dbuser; + private String dbpasswd; + private Statement stat; + private Connection con; + +/* + * Constructor establishes connection to Database Server + * + * @param db + * jdbc Connection to database + * @param dbYalpUser + * userName for database + * @param dbPasswd + * password for database + */ + public YalpAuthInterfaceImpl(String db, String dbYalpUser, String dbPasswd) { + try{ + this.dbuser = dbYalpUser; + this.dbpasswd = dbPasswd; + Class.forName("org.postgresql.Driver"); + con = DriverManager.getConnection(db,dbuser,dbpasswd); + System.out.println("YalpAuth: PGSQL connection established"); + this.stat= con.createStatement(); + } catch (SQLException e) { + System.out.println("Exception in DbConnection Constructor: "+e); + } catch (ClassNotFoundException e) { + System.out.println("Exception in DbConnection Constructor: "+e); + } + } + +/* + * checks if user exists in yalpYalpUser Database and what rights he has + * + * @param username + * username to check + * @param passwd + * password to check + * + * @return enum privilege level + */ + public int userVerify(String username,String passwd) { + try{ + ResultSet result=stat.executeQuery("select * from \"user\" where \"username\" = '"+username+"' and \"passwd\" = '"+passwd+"';"); + + if (result.next()){ + if (result.getBoolean(5)==true){ + return 2; + }else return 1; + }else return 0; + }catch (SQLException e){ + System.out.println("Exception in DbConnection.userVerify: "+e); + return 0; + } + } + +/* + * returns an ArrayList with all yalpYalpUsers and Admins + * + * @return ArrayList<YalpUser> + * list with all YalpYalpUsers and Admins + */ + public void getUser(UsersHolder list, YalpErrorHolder err) { + try { + ArrayList<YalpUser> resultList =new ArrayList<YalpUser>(); + YalpUser actUser = new YalpUser(); + String query = "select * from \"user\"order by \"id\";"; + Statement stat= con.createStatement(); + ResultSet result=stat.executeQuery(query); + + while(result.next()) + { + /* t.b.d. - create YalpUser according to new database design */ + // result.getInt(1),result.getString(2),result.getString(3),result.getString(4),result.getBoolean(5))) + resultList.add( actUser ); + } + YalpUser[] u = new YalpUser[1]; + list = new UsersHolder(resultList.toArray(u)); + } catch (SQLException e) { + YalpError error = new YalpError(); + error.code = YalpErrorCode.ERROR_SQL; + error.descr = e.toString(); + error.level = YalpErrorLevel.ERROR_LEVEL_ERROR; + err = new YalpErrorHolder(error); + } + } + +/* + * submits changes to yalpYalpUserDatabase + * + * @param change + * describes the change to commit + * @return int + * -1 if failed + */ + public void changeUser(YalpUser usr, String passwd, Action todo, + YalpError err) { + + /* t.b.d. alter to new db design + try{ + String sql; + switch (todo.type){ + // if updateType is UPDATE + case Action._UPDATE: + sql="update \"user\" set \"username\"='"+usr.name+"', \"passwd\"='"+change.passwd+"', \"realname\"='"+change.realname+"', \"admin\"="+change.admin+" where \"id\"= "+change.id+" ;"; + break; + // if updateType is INSERT INTO + case Action._INSERT: + sql="insert into \"user\" values(nextval('userId'), '"+usr+"','"+change.passwd+"','"+change.realname+"',"+change.admin+");"; + break; + // if updateType is DELETE + case Action._DELETE: + sql="delete from \"user\" where \"id\"= "+change.id+" ;"; + break; + default: + //errorhandling + } + // perform operation on table an return number of updated rows + System.out.println(sql); + return stat.executeUpdate(sql); + }catch(SQLException e){ + System.out.println("Exception in DbConnection.changeYalpUser: "+e); + } + */ + } +} diff --git a/src/YalpAuth/YalpPGSqlAuth/YalpPGSqlAuth.java b/src/YalpAuth/YalpPGSqlAuth/YalpPGSqlAuth.java new file mode 100644 index 0000000..53ddde1 --- /dev/null +++ b/src/YalpAuth/YalpPGSqlAuth/YalpPGSqlAuth.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2006 Manuel Traut and Volker Dahnke + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Manuel Traut and Volker Dahnke + */ +package YalpAuth.YalpPGSqlAuth; + +import YalpInterfaces.*; + +/* + * Class YalpPGSqlAuth + * + * <em>Implements functionality of the DBConnectionInterface</em> + * + * @author Volker Dahnke / Manuel Traut + * + * @version 1 02-04-2006<br> + */ + +public class YalpPGSqlAuth { + private YalpAuthInterfaceImpl con; + private DatabaseDefines config; + + public static void main(String[] args) + { + System.out.println("YalpPGSqlAuth\n"); + } +} |
