]> WPIA git - gigi.git/commitdiff
add: implement password change log
authorINOPIAE <m.maengel@inopiae.de>
Sat, 23 Feb 2019 05:40:54 +0000 (06:40 +0100)
committerINOPIAE <m.maengel@inopiae.de>
Wed, 11 Sep 2019 03:54:39 +0000 (05:54 +0200)
fixes issue #42

Change-Id: I64a8ab5ff675852029b19e2e325f8fcd738544d5

src/club/wpia/gigi/dbObjects/CertificateOwner.java
src/club/wpia/gigi/dbObjects/SupportedUser.java
src/club/wpia/gigi/dbObjects/User.java
src/club/wpia/gigi/pages/PasswordResetPage.java
src/club/wpia/gigi/pages/account/ChangeForm.java
src/club/wpia/gigi/pages/wot/VerificationForm.java
tests/club/wpia/gigi/dbObjects/TestUser.java
tests/club/wpia/gigi/pages/account/TestChangePassword.java
tests/club/wpia/gigi/pages/account/TestPasswordResetExternal.java
tests/club/wpia/gigi/pages/admin/TestSEAdminNotificationMail.java
tests/club/wpia/gigi/testUtils/ArrayContains.java [new file with mode: 0644]

index 72e5a81672762a74510cfbe7743dda61f19d2231..5801f602f5c9ee59b4eedfd82fd6041eaede54f0 100644 (file)
@@ -134,7 +134,11 @@ public abstract class CertificateOwner implements IdCachable, Serializable {
             List<String> entries = new LinkedList<String>();
 
             while (res.next()) {
             List<String> entries = new LinkedList<String>();
 
             while (res.next()) {
-                entries.add(res.getString(2) + " (" + res.getString(3) + ")");
+                String info = res.getString(3);
+                if ( !info.isEmpty()) {
+                    info = " (" + info + ")";
+                }
+                entries.add(res.getString(2) + info);
             }
             return entries.toArray(new String[0]);
         }
             }
             return entries.toArray(new String[0]);
         }
index 5d023e9bbb68a90ea612fd47d3e659199cb86e44..84c43ab8e0db5261d745d200d34d69663be20ef8 100644 (file)
@@ -175,13 +175,14 @@ public class SupportedUser {
         }
     }
 
         }
     }
 
-    public void triggerPasswordReset(String aword, HttpServletRequest req) {
+    public void triggerPasswordReset(String aword, HttpServletRequest req) throws GigiApiException {
         Language l = Language.getInstance(target.getPreferredLocale());
         String method = l.getTranslation("A password reset was triggered. Please enter the required text sent to you by support on this page:");
         String subject = l.getTranslation("Password reset by support.");
         PasswordResetPage.initPasswordResetProcess(target, req, aword, l, method, subject);
         Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
         sendSupportNotification(subject, message);
         Language l = Language.getInstance(target.getPreferredLocale());
         String method = l.getTranslation("A password reset was triggered. Please enter the required text sent to you by support on this page:");
         String subject = l.getTranslation("Password reset by support.");
         PasswordResetPage.initPasswordResetProcess(target, req, aword, l, method, subject);
         Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
         sendSupportNotification(subject, message);
+        writeSELog("SE triggered password reset");
     }
 
     private void sendBoardNotification(String subject, Outputable message) {
     }
 
     private void sendBoardNotification(String subject, Outputable message) {
index 3b4f4671d2a01b8462e2c0b6238ea7c48b7e3d0a..e3beaf86cf65ba2bd6a38eb883996d48859a455b 100644 (file)
@@ -700,4 +700,13 @@ public class User extends CertificateOwner {
     public boolean hasValidTTPAgentChallenge() {
         return CATS.isInCatsLimit(getId(), CATSType.TTP_AGENT_CHALLENGE.getId());
     }
     public boolean hasValidTTPAgentChallenge() {
         return CATS.isInCatsLimit(getId(), CATSType.TTP_AGENT_CHALLENGE.getId());
     }
+
+    public void writeUserLog(User actor, String type) throws GigiApiException {
+        try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `adminLog` SET uid=?, admin=?, type=?")) {
+            prep.setInt(1, actor.getId());
+            prep.setInt(2, getId());
+            prep.setString(3, type);
+            prep.executeUpdate();
+        }
+    }
 }
 }
index af1829a09223f504fc3bfcfec424d5d0c9acaced..b5132f058558da45548c9ce0543f979f18f19469 100644 (file)
@@ -76,6 +76,7 @@ public class PasswordResetPage extends Page {
                 throw new GigiApiException("New passwords differ.");
             }
             u.consumePasswordResetTicket(id, tok, p1);
                 throw new GigiApiException("New passwords differ.");
             }
             u.consumePasswordResetTicket(id, tok, p1);
+            u.writeUserLog(u, "User token based password reset");
             return new SuccessMessageResult(new TranslateCommand("Password reset successful."));
         }
 
             return new SuccessMessageResult(new TranslateCommand("Password reset successful."));
         }
 
index 53c04de600f321c83e968157c4a29fe11cf731ea..de2a182d6bd7aa1348670f91321a3b412fb28750 100644 (file)
@@ -42,6 +42,7 @@ public class ChangeForm extends Form {
         }
         try {
             target.changePassword(oldpassword, p1);
         }
         try {
             target.changePassword(oldpassword, p1);
+            target.writeUserLog(target, "User triggered password reset");
         } catch (GigiApiException e) {
             error.mergeInto(e);
         }
         } catch (GigiApiException e) {
             error.mergeInto(e);
         }
index 327b6eb530e734615a96f6f1bfbc8b64a3a9a5a7..78ddcea1911c9d426698eb0bd49ee8c4501de25f 100644 (file)
@@ -228,6 +228,7 @@ public class VerificationForm extends Form {
             String subject = langApplicant.getTranslation("Password reset by verification");
             PasswordResetPage.initPasswordResetProcess(applicant, req, aword, langApplicant, method, subject);
             result = new ConcatOutputable(result, new TranslateCommand("Password reset successful."));
             String subject = langApplicant.getTranslation("Password reset by verification");
             PasswordResetPage.initPasswordResetProcess(applicant, req, aword, langApplicant, method, subject);
             result = new ConcatOutputable(result, new TranslateCommand("Password reset successful."));
+            agent.writeUserLog(applicant, "RA Agent triggered password reset");
         }
         return new SuccessMessageResult(result);
     }
         }
         return new SuccessMessageResult(result);
     }
index ed3f1c951b3df52d3dd31ad693df7227e7a4b83d..6ec0abecd260381db8a32a64601194072cc0114f 100644 (file)
@@ -6,11 +6,13 @@ import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.sql.Date;
 
 import java.security.GeneralSecurityException;
 import java.sql.Date;
 
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
+import club.wpia.gigi.testUtils.ArrayContains;
 import club.wpia.gigi.testUtils.ClientBusinessTest;
 
 public class TestUser extends ClientBusinessTest {
 import club.wpia.gigi.testUtils.ClientBusinessTest;
 
 public class TestUser extends ClientBusinessTest {
@@ -105,4 +107,18 @@ public class TestUser extends ClientBusinessTest {
         assertTrue(u.hasValidTTPAgentChallenge());
     }
 
         assertTrue(u.hasValidTTPAgentChallenge());
     }
 
+    @Test
+    public void testWriteUserLog() throws GigiApiException {
+        String type = "Log test";
+        u.writeUserLog(u, type);
+        String[] result = u.getAdminLog();
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type)));
+
+        String type1 = "Log test1";
+        u.writeUserLog(u, type1);
+        result = u.getAdminLog();
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type1)));
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type)));
+    }
+
 }
 }
index 7a2a6a923f7187f0d7e5bc018f55216713529b4d..e18ec02a5ea5be4f108d1423fda46e0a3bc23f99 100644 (file)
@@ -5,10 +5,11 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 import java.net.URLEncoder;
 
 import java.io.IOException;
 import java.net.URLEncoder;
 
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
-import club.wpia.gigi.pages.account.ChangePasswordPage;
+import club.wpia.gigi.testUtils.ArrayContains;
 import club.wpia.gigi.testUtils.ClientTest;
 
 public class TestChangePassword extends ClientTest {
 import club.wpia.gigi.testUtils.ClientTest;
 
 public class TestChangePassword extends ClientTest {
@@ -44,6 +45,9 @@ public class TestChangePassword extends ClientTest {
         assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2")));
         assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD)));
 
         assertTrue(isLoggedin(login(u.getEmail(), TEST_PASSWORD + "v2")));
         assertFalse(isLoggedin(login(u.getEmail(), TEST_PASSWORD)));
 
+        String[] result = u.getAdminLog();
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo("User triggered password reset")));
+
     }
 
     @Test
     }
 
     @Test
index 31510abeb65b876a51ed2338a0810bcf378deb42..439c0f5b7401b7ad842b555cf249cf26f097a419 100644 (file)
@@ -12,12 +12,14 @@ import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.security.GeneralSecurityException;
 
 import java.net.URLEncoder;
 import java.security.GeneralSecurityException;
 
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.pages.PasswordResetPage;
 import club.wpia.gigi.pages.wot.TestVerification;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.pages.PasswordResetPage;
 import club.wpia.gigi.pages.wot.TestVerification;
+import club.wpia.gigi.testUtils.ArrayContains;
 import club.wpia.gigi.testUtils.ClientTest;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
 import club.wpia.gigi.testUtils.ClientTest;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -46,6 +48,10 @@ public class TestPasswordResetExternal extends ClientTest {
         assertNotNull(toPasswordReset(avalue, link, "a", "a"));
         assertNull(toPasswordReset(avalue, link, npw, npw));
         assertNotNull(login(email, npw));
         assertNotNull(toPasswordReset(avalue, link, "a", "a"));
         assertNull(toPasswordReset(avalue, link, npw, npw));
         assertNotNull(login(email, npw));
+
+        String[] result = this.u.getAdminLog();
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo("RA Agent triggered password reset")));
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo("User token based password reset")));
     }
 
     private String toPasswordReset(String avalue, String link, String npw, String npw2) throws IOException, MalformedURLException, UnsupportedEncodingException {
     }
 
     private String toPasswordReset(String avalue, String link, String npw, String npw2) throws IOException, MalformedURLException, UnsupportedEncodingException {
index 180455cec7a93ec7e2fa4c79da3ff3f1f643ecc2..a84e0e2f7c0cbaddecf5c383eab4a8e04e9c86b7 100644 (file)
@@ -12,6 +12,7 @@ import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Locale;
 
 import java.util.HashMap;
 import java.util.Locale;
 
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
@@ -20,6 +21,7 @@ import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.localisation.Language;
 import club.wpia.gigi.pages.account.MyDetails;
 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
 import club.wpia.gigi.localisation.Language;
 import club.wpia.gigi.pages.account.MyDetails;
 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
+import club.wpia.gigi.testUtils.ArrayContains;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.SEClientTest;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
 import club.wpia.gigi.testUtils.IOUtils;
 import club.wpia.gigi.testUtils.SEClientTest;
 import club.wpia.gigi.testUtils.TestEmailReceiver.TestMail;
@@ -59,6 +61,10 @@ public class TestSEAdminNotificationMail extends SEClientTest {
         getMailReceiver().receive(targetEmail);
         TestMail tm = getMailReceiver().receive(ServerConstants.getSupportMailAddress());
         assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
         getMailReceiver().receive(targetEmail);
         TestMail tm = getMailReceiver().receive(ServerConstants.getSupportMailAddress());
         assertThat(tm.getMessage(), containsString("A password reset was triggered and an email was sent to user."));
+
+        User test = User.getById(targetID);
+        String[] result = test.getAdminLog();
+        assertThat(result, ArrayContains.contains(CoreMatchers.equalTo("SE triggered password reset (a20140808.8)")));
     }
 
     @Test
     }
 
     @Test
diff --git a/tests/club/wpia/gigi/testUtils/ArrayContains.java b/tests/club/wpia/gigi/testUtils/ArrayContains.java
new file mode 100644 (file)
index 0000000..12755b4
--- /dev/null
@@ -0,0 +1,35 @@
+package club.wpia.gigi.testUtils;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+
+public class ArrayContains<T> extends BaseMatcher<T[]> {
+
+    Matcher<T> containee;
+
+    public ArrayContains(Matcher<T> containee) {
+        this.containee = containee;
+    }
+
+    @Override
+    public boolean matches(Object item) {
+        Object[] array = (Object[]) item;
+        for (Object t : array) {
+            if (containee.matches(t)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText("contains an element that:");
+        containee.describeTo(description);
+    }
+
+    public static <T> ArrayContains<T> contains(final Matcher<T> element) {
+        return new ArrayContains<T>(element);
+    }
+}