# HG changeset patch # User Jaroslav Tulach # Date 1272224460 -7200 # Node ID a47345ebbdd764f2436b2a55c6d0cf274b54837a # Parent a4f6aca595e80149b43f44a25d962e43cad4fa7f Password can be stored in user properties diff -r a4f6aca595e8 -r a47345ebbdd7 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sun Apr 25 21:20:09 2010 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sun Apr 25 21:41:00 2010 +0200 @@ -90,7 +90,7 @@ public String login( @QueryParam("name") String name, @QueryParam("password") String password - ) { + ) throws IOException { File f = new File(path, "passwd"); // NOI18Nt Properties p = new Properties(); try { @@ -98,7 +98,14 @@ } catch (IOException ex) { ex.printStackTrace(); } + boolean loggedInOK = false; if (name != null && password.equals(p.getProperty(name))) { + loggedInOK = true; + } else { + loggedInOK = getUsers().verifyPassword(name, password); + } + + if (loggedInOK) { UUID uuid = UUID.randomUUID(); loggedIn.put(uuid, name); return uuid.toString(); diff -r a4f6aca595e8 -r a47345ebbdd7 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java Sun Apr 25 21:20:09 2010 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Users.java Sun Apr 25 21:41:00 2010 +0200 @@ -131,6 +131,14 @@ return Response.ok().entity(getUserInfo(null, loginId, id).getJsonSource()).build(); } + final boolean verifyPassword(String id, String passwd) throws IOException { + Properties p = getProp(id); + if (p != null) { + return passwd.equals(p.getProperty("passwd")); + } + return false; + } + private synchronized Properties getProp(String id) throws FileNotFoundException, IOException { Properties p = new Properties(); if (id != null && id.length() > 0) { diff -r a4f6aca595e8 -r a47345ebbdd7 webidor/src/test/java/cz/xelfi/quoridor/webidor/UsersTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/UsersTest.java Sun Apr 25 21:20:09 2010 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/UsersTest.java Sun Apr 25 21:41:00 2010 +0200 @@ -26,6 +26,7 @@ package cz.xelfi.quoridor.webidor; +import java.io.FileInputStream; import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.test.framework.JerseyTest; import java.io.File; @@ -59,8 +60,17 @@ dir.mkdirs(); File passwd = new File(dir, "passwd"); FileOutputStream os = new FileOutputStream(passwd); - os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8")); + os.write("Jarda=heslo\n".getBytes("UTF-8")); os.close(); + File usersDir = new File(dir, "users"); + usersDir.mkdirs(); + File fJirka = new File(usersDir, "Jirka"); + { + Properties p = new Properties(); + p.setProperty("email", "jir@ka.cz"); + p.setProperty("passwd", "pesko"); + p.store(new FileOutputStream(fJirka), ""); + } super.setUp(); } @@ -95,6 +105,7 @@ File fJirka = new File(usersDir, "Jirka"); { Properties p = new Properties(); + p.load(new FileInputStream(fJirka)); p.setProperty("email", "jir@ka.cz"); p.store(new FileOutputStream(fJirka), ""); }