]> WPIA git - gigi.git/commitdiff
add: ensure that for OrgAdmin action there is a valid OrgAdmin Challenge
authorINOPIAE <m.maengel@inopiae.de>
Thu, 18 Jul 2019 05:43:48 +0000 (07:43 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 8 Sep 2019 19:32:34 +0000 (21:32 +0200)
last patch of series. Fixes issue #150

Change-Id: I17bf8fd5ea9af89792d6ac4fe8f39261e8aa0192

src/club/wpia/gigi/pages/MainPage.java
src/club/wpia/gigi/pages/MainPage.templ
src/club/wpia/gigi/pages/orga/MyOrganisationsForm.java
src/club/wpia/gigi/pages/orga/SwitchOrganisation.java
src/club/wpia/gigi/pages/orga/ViewOrgPage.java
tests/club/wpia/gigi/pages/TestMain.java
tests/club/wpia/gigi/pages/orga/TestOrgDomain.java
tests/club/wpia/gigi/pages/orga/TestOrgSwitch.java

index 9ebd30fa5b28f4994534e019a40dd7cc4c105d41..02232f2e412808663388d95ed851ed5e06d15ae3 100644 (file)
@@ -128,6 +128,11 @@ public class MainPage extends Page {
                 vars.put("certlogininfo", false);
             }
 
+            if ( !o.isEmpty() && !u.hasValidOrgAdminChallenge()) {
+                vars.put("catsinfo", true);
+                vars.put("catsorgadmin", true);
+            }
+
             getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
 
         } else {
index 9b7ea86e4430f823fd2243ffd570aaa82999968f..963208e803a8aecb46b78de23379740f5d68bfa9 100644 (file)
   <? if($catsorgagent) { ?>
     <p><?=_To act as Organisation Agent you need to pass the Organisation Agent Challenge.?></p>
   <? } ?>
-    <? if($catsttpagent) { ?>
-      <p><?=_To act as TTP Agent you need to pass the TTP RA Agent Challenge.?></p>
-    <? } ?>
+  <? if($catsttpagent) { ?>
+    <p><?=_To act as TTP Agent you need to pass the TTP RA Agent Challenge.?></p>
+  <? } ?>
+  <? if($catsorgadmin) { ?>
+    <p><?=_To act as Organisation Administrator you need to pass the Organisation Administrator Challenge.?></p>
+  <? } ?>
   </div>
 <? } ?>
 <div class="card card-body bg-light">
index a083b7cd343c56842c1a165b55abff108296c82c..d5a6710819adeb29aae7e3c2987c7c88bc52c926 100644 (file)
@@ -62,7 +62,7 @@ public class MyOrganisationsForm extends Form {
     @Override
     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
         final List<Organisation> o = target.getActor().getOrganisations();
-        vars.put("certlogin", target.isStronglyAuthenticated());
+        vars.put("certlogin", target.isStronglyAuthenticated() && target.getActor().hasValidOrgAdminChallenge());
         if (target.getTarget() != target.getActor()) {
             vars.put("personal", target.getTarget() != target.getActor());
         }
index 1d680ca092cbba2ae8e59ac9a3c05fd64e4b8658..16ccbf434f5018190aea3a5a87c885ce1ba6985c 100644 (file)
@@ -19,7 +19,7 @@ public class SwitchOrganisation extends ManagedFormPage {
 
     @Override
     public boolean isPermitted(AuthorizationContext ac) {
-        return ac != null && ac.getActor().getOrganisations().size() != 0 && ac.isStronglyAuthenticated();
+        return ac != null && ac.getActor().getOrganisations().size() != 0 && ac.isStronglyAuthenticated() && ac.getActor().hasValidOrgAdminChallenge();
     }
 
     @Override
index 03274215e6158e1bb81565542435a9c66f91a45c..de4e9d043691033f6e232f151cc5a6192ecf0c1a 100644 (file)
@@ -36,7 +36,7 @@ public class ViewOrgPage extends ManagedMultiFormPage {
 
     @Override
     public boolean isPermitted(AuthorizationContext ac) {
-        return ac != null && ((ac.isInGroup(CreateOrgPage.ORG_AGENT) && ac.getActor().hasValidOrgAgentChallenge()) || ac.getActor().getOrganisations(true).size() != 0) && ac.isStronglyAuthenticated();
+        return ac != null && ((ac.isInGroup(CreateOrgPage.ORG_AGENT) && ac.getActor().hasValidOrgAgentChallenge()) || (ac.getActor().getOrganisations(true).size() != 0) && ac.getActor().hasValidOrgAdminChallenge()) && ac.isStronglyAuthenticated();
     }
 
     @Override
index dfc6579e07139d780b5c35fc167f488f7e1cccc0..be642f03101825d549f33493e76a484cf58192a6 100644 (file)
@@ -147,9 +147,26 @@ public class TestMain extends ClientTest {
 
         addChallenge(u.getId(), CATSType.TTP_AGENT_CHALLENGE);
         testChallengeText("you need to pass the TTP RA Agent Challenge", false);
+
+        // test Org Admin Challenge
+        Organisation o = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
+        User admin = User.getById(createVerificationUser("testworker", "testname", createUniqueName() + "@testdom.com", TEST_PASSWORD));
+
+        loginCertificate = null;
+        cookie = cookieWithCertificateLogin(admin);
+        testChallengeText("you need to pass the Organisation Administrator Challenge", false);
+
+        o.addAdmin(admin, u, true);
+        testChallengeText("you need to pass the Organisation Administrator Challenge", true);
+
+        addChallengeInPast(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
+        testChallengeText("you need to pass the Organisation Administrator Challenge", true);
+
+        addChallenge(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
+        testChallengeText("you need to pass the Organisation Administrator Challenge", false);
     }
 
-    private void testChallengeText(String contentText, boolean contains) throws IOException, MalformedURLException {
+    private void testChallengeText(String contentText, boolean contains) throws IOException, MalformedURLException, GigiApiException {
         URLConnection uc = new URL("https://" + getSecureServerName()).openConnection();
         authenticate((HttpURLConnection) uc);
         String content = IOUtils.readURL(uc);
index f04f66ae3fbc1e78312a9cd2c7c0f48c4b7ed46d..97b8fbe7b7eac2283002cecb6dc5305555e9ca87 100644 (file)
@@ -10,6 +10,7 @@ import java.net.URLEncoder;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.CATS.CATSType;
 import club.wpia.gigi.dbObjects.Domain;
 import club.wpia.gigi.dbObjects.Organisation;
 import club.wpia.gigi.dbObjects.User;
@@ -99,6 +100,7 @@ public class TestOrgDomain extends OrgTest {
         Domain d = new Domain(u, o, dom);
         assertEquals(1, o.getDomains().length);
         User admin = createOrgAdmin(o);
+        addChallenge(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
         String adminCookie = cookieWithCertificateLogin(admin);
         assertNull(executeBasicWebInteraction(adminCookie, SwitchOrganisation.PATH, "org:" + o.getId() + "=y", 0));
 
index 90362a9a8cac0be7a2e954e6258bc61715507a70..c19f387c38e28d7e7f6ac1c6b1993e80afa06267 100644 (file)
@@ -8,12 +8,18 @@ import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
 import java.sql.SQLException;
 
 import org.junit.After;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.CATS.CATSType;
+import club.wpia.gigi.dbObjects.Certificate;
 import club.wpia.gigi.dbObjects.Organisation;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.testUtils.IOUtils;
@@ -27,6 +33,10 @@ public class TestOrgSwitch extends OrgTest {
 
     private Organisation org2 = createUniqueOrg();
 
+    private Certificate cagent;
+
+    private PrivateKey pkagent;
+
     public TestOrgSwitch() throws IOException, GigiApiException {
 
         assertEquals(403, get(SwitchOrganisation.PATH).getResponseCode());
@@ -35,6 +45,9 @@ public class TestOrgSwitch extends OrgTest {
         u2 = User.getById(createVerificationUser("testworker", "testname", email, TEST_PASSWORD));
         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org1.getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1));
         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org2.getId(), "email=" + URLEncoder.encode(u2.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1));
+        addChallenge(u2.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
+        cagent = loginCertificate;
+        pkagent = loginPrivateKey;
 
         // login with new user u2
         cookie = cookieWithCertificateLogin(u2);
@@ -127,4 +140,24 @@ public class TestOrgSwitch extends OrgTest {
         URLConnection uc = get(cookie, SwitchOrganisation.PATH);
         assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
     }
+
+    @Test
+    public void testSwitchOrgLoginChallenge() throws IOException, GigiApiException, KeyManagementException, NoSuchAlgorithmException, GeneralSecurityException {
+        loginCertificate = cagent;
+        loginPrivateKey = pkagent;
+        cookie = login(pkagent, cagent.cert());
+        String email = createUniqueName() + "@testdom.com";
+        User u3 = User.getById(createVerificationUser("testworker", "testname", email, TEST_PASSWORD));
+        assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org1.getId(), "email=" + URLEncoder.encode(u3.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1));
+        assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + org2.getId(), "email=" + URLEncoder.encode(u3.getEmail(), "UTF-8") + "&do_affiliate=y&master=y", 1));
+
+        cookie = cookieWithCertificateLogin(u3);
+        URLConnection uc = get(cookie, SwitchOrganisation.PATH);
+        assertEquals(403, ((HttpURLConnection) uc).getResponseCode());
+
+        addChallenge(u3.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
+        clearCaches();
+        uc = get(cookie, SwitchOrganisation.PATH);
+        assertEquals(200, ((HttpURLConnection) uc).getResponseCode());
+    }
 }