Generalized http authentication framework.
Change-Id: I99b9bdb8b93445ceaf51ecb8105a23f980408df2
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java b/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java
index aa213d2..aea4968 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java
@@ -1,21 +1,25 @@
package de.ids_mannheim.korap.config;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
-import de.ids_mannheim.korap.utils.StringUtils;
-import org.apache.commons.codec.binary.Base64;
-import org.junit.Test;
-
-import java.util.Arrays;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import de.ids_mannheim.korap.authentication.BasicAuthentication;
+import de.ids_mannheim.korap.authentication.framework.AuthorizationData;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.authentication.framework.TransferEncoding;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.StringUtils;
/**
* Created by hanl on 29.05.16.
*/
public class StringUtilsTest {
+
@Test
public void testTextIToDoc () {
String textSigle = "WPD_AAA.02439";
@@ -26,17 +30,19 @@
@Test
- public void testBasicHttpSplit() {
- String s1 = "basic " + new String(Base64.encodeBase64("test:testPass".getBytes()));
- String s2 = new String(Base64.encodeBase64("test:testPass".getBytes()));
- String[] f1 = BasicHttpAuth.decode(s1);
- String[] f2 = BasicHttpAuth.decode(s2);
- assertNotNull(f1);
- assertNotNull(f2);
- assertEquals("test", f1[0]);
- assertEquals("testPass", f1[1]);
- assertEquals("test", f2[0]);
- assertEquals("testPass", f2[1]);
+ public void testBasicHttpSplit () throws KustvaktException {
+ TransferEncoding transferEncoding = new TransferEncoding();
+ String s2 = new String(Base64.encodeBase64("test:testPass".getBytes()));
+ String[] f2 = transferEncoding.decodeBase64(s2);
+ assertEquals("test", f2[0]);
+ assertEquals("testPass", f2[1]);
+
+
+ HttpAuthorizationHandler handler = new HttpAuthorizationHandler();
+ String s1 = "basic "
+ + new String(Base64.encodeBase64("test:testPass".getBytes()));
+ AuthorizationData f1 = handler.parseAuthorizationHeader(s1);
+ assertEquals(s2, f1.getToken());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
index a314d7f..1acf4c2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
@@ -9,12 +9,15 @@
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.authentication.framework.TransferEncoding;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -31,8 +34,12 @@
@Ignore
public class AuthServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
private static String[] credentials;
-
+
+
@BeforeClass
public static void configure () throws Exception {
credentials = new String[2];
@@ -54,7 +61,8 @@
@Test
public void testSessionToken() throws KustvaktException {
- String auth = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String auth = handler.createAuthorizationHeader(AuthenticationType.SESSION,
+ credentials[0], credentials[1]);
ClientResponse response = resource().path("auth")
.path("sessionToken").header(Attributes.AUTHORIZATION, auth)
.get(ClientResponse.class);
@@ -90,7 +98,8 @@
@Test
public void testSessionTokenExpire() throws KustvaktException {
- String auth = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String auth = handler.createAuthorizationHeader(AuthenticationType.SESSION,
+ credentials[0], credentials[1]);
ClientResponse response = resource().path("auth")
.path("sessionToken").header(Attributes.AUTHORIZATION, auth)
.get(ClientResponse.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
index ed1eec6..765deb8 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
@@ -1,18 +1,22 @@
package de.ids_mannheim.korap.web.service.full;
-import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.config.TestHelper;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.jetty.server.Response;
-import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
-import static org.junit.Assert.assertEquals;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
+import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
/** EM: fix tests. new DB does not save users.
* @author hanl
@@ -21,13 +25,19 @@
@Ignore
public class FilterTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
+
@Test
- public void testTestUserAuth () {
+ public void testTestUserAuth () throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+
ClientResponse resp = resource()
.path("user/info")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode(
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,
(String) TestHelper.getUserCredentials().get(Attributes.USERNAME),
(String) TestHelper.getUserCredentials().get(Attributes.PASSWORD)))
.get(ClientResponse.class);
@@ -45,12 +55,14 @@
@Test
- public void testUnauthorizedAuth () {
+ public void testUnauthorizedAuth () throws UniformInterfaceException,
+ ClientHandlerException, KustvaktException {
+
ClientResponse resp = resource()
-
.path("user/info")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,
+ "kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
String entity = resp.getEntity(String.class);
System.out.println(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
index a265cfa..31248d8 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktServerTest.java
@@ -27,14 +27,17 @@
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.authentication.framework.TransferEncoding;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.BeanConfigTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.handlers.ResourceDao;
@@ -60,6 +63,8 @@
@Deprecated
public class KustvaktServerTest extends BeanConfigTest {
private static ObjectMapper mapper = new ObjectMapper();
+ @Autowired
+ private HttpAuthorizationHandler handler;
@Test
@@ -170,7 +175,7 @@
@Test
- public void testCreatePolicy () throws IOException, URISyntaxException {
+ public void testCreatePolicy () throws IOException, URISyntaxException, KustvaktException {
HttpClient httpClient = HttpClients.createDefault();
@@ -189,7 +194,7 @@
HttpPost httppost = new HttpPost(uri);
httppost.addHeader(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"));
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"));
HttpResponse response = httpClient.execute(httppost);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatusLine().getStatusCode());
@@ -199,7 +204,7 @@
@Test
public void testCreatePolicyForFoundry ()
- throws IOException, URISyntaxException {
+ throws IOException, URISyntaxException, KustvaktException {
HttpClient httpClient = HttpClients.createDefault();
@@ -219,7 +224,7 @@
HttpPost httppost = new HttpPost(uri);
httppost.addHeader(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"));
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"));
HttpResponse response = httpClient.execute(httppost);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatusLine().getStatusCode());
@@ -229,7 +234,7 @@
@Test
public void testCreatePolicyWithMultiplePermissions ()
- throws IOException, URISyntaxException {
+ throws IOException, URISyntaxException, KustvaktException {
HttpClient httpClient = HttpClients.createDefault();
@@ -250,7 +255,7 @@
HttpPost httppost = new HttpPost(uri);
httppost.addHeader(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"));
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"));
HttpResponse response = httpClient.execute(httppost);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatusLine().getStatusCode());
@@ -260,7 +265,7 @@
@Test
public void testWrongAuthorization ()
- throws IOException, URISyntaxException {
+ throws IOException, URISyntaxException, KustvaktException {
HttpResponse response = testResourceStore("wezrowerowj");
assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(),
response.getStatusLine().getStatusCode());
@@ -297,7 +302,7 @@
public HttpResponse testResourceStore (String password)
- throws IOException, URISyntaxException {
+ throws IOException, URISyntaxException, KustvaktException {
HttpClient httpclient = HttpClients.createDefault();
URIBuilder builder = new URIBuilder();
@@ -309,14 +314,14 @@
URI uri = builder.build();
HttpPost httppost = new HttpPost(uri);
httppost.addHeader(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", password));
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", password));
return httpclient.execute(httppost);
}
@Test
public void testResourceUpdate ()
- throws IOException, URISyntaxException {
+ throws IOException, URISyntaxException, KustvaktException {
HttpClient httpclient = HttpClients.createDefault();
URIBuilder builder = new URIBuilder();
@@ -328,7 +333,7 @@
URI uri = builder.build();
HttpPost httppost = new HttpPost(uri);
httppost.addHeader(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"));
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"));
HttpResponse response = httpclient.execute(httppost);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
index 66f38fb..28318cf 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -6,18 +6,23 @@
import org.eclipse.jetty.http.HttpHeaders;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
public class MatchInfoServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Test
public void testGetMatchInfoPublicCorpus () throws KustvaktException {
@@ -72,7 +77,8 @@
.path("p36875-36876").path("matchInfo")
.queryParam("foundry", "*")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(
+ AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
.get(ClientResponse.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
index d4c8aa1..18bae77 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/OAuth2EndpointTest.java
@@ -6,14 +6,17 @@
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.authentication.framework.TransferEncoding;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -26,7 +29,9 @@
@Ignore
// todo: in combination with other tests, causes failures!
public class OAuth2EndpointTest extends FastJerseyTest {
-
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Override
public void initMethod () throws KustvaktException {
// helper().setupAccount();
@@ -35,7 +40,8 @@
@Test
public void testAuthorizeClient () throws ClientHandlerException, UniformInterfaceException, KustvaktException {
- String auth = BasicHttpAuth.encode(helper().getUser().getUsername(),
+ String auth = handler.createAuthorizationHeader(
+ AuthenticationType.OAUTH2, helper().getUser().getUsername(),
(String) TestHelper.getUserCredentials().get(Attributes.PASSWORD));
ClientResponse response = resource().path(getAPIVersion()).path("oauth2")
.path("register")
@@ -72,7 +78,8 @@
@Ignore
public void authenticate () throws KustvaktException {
Map<String, Object> cred = TestHelper.getUserCredentials();
- String enc = BasicHttpAuth.encode((String) cred.get(Attributes.USERNAME), (String) cred.get(Attributes.PASSWORD));
+ String enc = handler.createAuthorizationHeader(AuthenticationType.OAUTH2,
+ (String) cred.get(Attributes.USERNAME), (String) cred.get(Attributes.PASSWORD));
ClientResponse response = resource().path(getAPIVersion()).path("oauth2")
.path("register")
.queryParam("redirect_url", "korap.ids-mannheim.de/redirect")
@@ -94,7 +101,7 @@
.queryParam("response_type", "code")
.queryParam("redirect_uri", "korap.ids-mannheim.de/redirect")
// .header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", "application/x-www-form-urlencoded")
+ .header("Content-Type", "application/x-www-form-urlencodeBase64d")
.post(ClientResponse.class);
e = response.getEntity(String.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
index 7bc7910..58affbf 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/PolicyServiceTest.java
@@ -6,14 +6,15 @@
import java.util.List;
import java.util.UUID;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
@@ -35,6 +36,9 @@
@Ignore
public class PolicyServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
private User user = UserFactory.getDemoUser();
@@ -51,7 +55,7 @@
.queryParam("perm", Permission.READ.name())
.queryParam("expire", "")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -95,7 +99,7 @@
.queryParam("loc", "255.255.255.0")
.queryParam("expire", "30D")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -133,7 +137,7 @@
.queryParam("perm", Permission.DELETE.name())
.queryParam("expire", "30D")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
index e12c483..77bad19 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
@@ -12,15 +12,16 @@
import java.util.Iterator;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
@@ -30,6 +31,9 @@
@Ignore
public class QuerySerializationServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Override
public void initMethod () throws KustvaktException {
// helper().runBootInterfaces();
@@ -95,7 +99,7 @@
.path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
.queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -119,7 +123,7 @@
.queryParam("name", "Weimarer Werke")
.queryParam("description", "Goethe-Werke in Weimar (seit 1775)")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -136,7 +140,7 @@
.path("collection")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -161,7 +165,7 @@
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("context", "base/s:s")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
index 0209107..b357adb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
@@ -5,15 +5,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
@@ -25,6 +26,9 @@
@Ignore
public class ResourceInfoServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Override
public void initMethod () throws KustvaktException {
// helper().runBootInterfaces();
@@ -48,7 +52,7 @@
ClientResponse response = resource().path(getAPIVersion())
.path("collection")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
index 8759b33..238e7ba 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
@@ -9,16 +9,17 @@
import org.apache.http.HttpStatus;
import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.handlers.ResourceDao;
import de.ids_mannheim.korap.resources.KustvaktResource;
@@ -35,7 +36,9 @@
@Deprecated
public class ResourceServiceTest extends FastJerseyTest {
-
+ @Autowired
+ HttpAuthorizationHandler handler;
+
// create a simple test collection for user kustvakt, otherwise test fails
@Test
@Ignore
@@ -43,7 +46,7 @@
ClientResponse response = resource().path(getAPIVersion())
.path("collection")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -56,7 +59,7 @@
response = resource().path(getAPIVersion()).path("collection").path(id)
.path("stats")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -76,7 +79,7 @@
.path("virtualcollection").path("GOE-VC") // persistent id
.queryParam("name", "Goethe collection")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -101,7 +104,7 @@
.path("corpus").path("GOE") // persistent id
.queryParam("name", "Goethe corpus")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -124,7 +127,7 @@
.path("foundry").path("malt") // persistent id
.queryParam("name", "malt parser")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -146,7 +149,7 @@
ClientResponse response = resource().path(getAPIVersion()).path("layer")
.path("mate/d").queryParam("name", "Mate dependency")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -169,7 +172,7 @@
.path("corpus").path("GOEC") // persistent id
.queryParam("name", "Goethe corpus")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
@@ -205,7 +208,7 @@
.queryParam("name", "Brown")
.queryParam("description", "Brown corpus")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -239,7 +242,7 @@
.queryParam("name", "Brown")
.queryParam("description", "Brown corpus")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
@@ -264,7 +267,7 @@
.queryParam("query", "author ~ Asdert")
.queryParam("description", "Wikipedia subcorpus from Asdert")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -300,7 +303,7 @@
.queryParam("name", "Goethe")
.queryParam("description", "Goethe corpus")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -330,7 +333,7 @@
response = resource().path(getAPIVersion()).path("virtualcollection")
.path(id).queryParam("name", "Goethe")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
@@ -343,7 +346,7 @@
response = resource().path(getAPIVersion()).path("virtualcollection")
.path(id).queryParam("name", "Goethe collection")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.post(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -358,7 +361,7 @@
response = resource().path(getAPIVersion()).path("virtualcollection")
.path(id)
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.delete(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index 380a316..ba2fb3c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -11,15 +11,16 @@
import javax.ws.rs.core.MediaType;
import org.eclipse.jetty.http.HttpHeaders;
-import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
@@ -37,6 +38,9 @@
*/
public class SearchServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Override
public void initMethod () throws KustvaktException {
// helper().runBootInterfaces();
@@ -139,7 +143,7 @@
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -165,7 +169,7 @@
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -197,7 +201,7 @@
.queryParam("ql", "poliqarp")
.queryParam("cq", "textClass=politik & corpusSigle=BRZ10")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -226,7 +230,7 @@
.path("search").queryParam("q", "[orth=die]")
.queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -360,7 +364,7 @@
.path("corpus").path("GOE").path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -402,7 +406,7 @@
.path("corpus").path(id).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
index 8837d18..7328064 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
@@ -5,18 +5,24 @@
import org.eclipse.jetty.http.HttpHeaders;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
public class SearchWithAvailabilityTest extends FastJerseyTest {
-
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Override
public void initMethod () throws KustvaktException {
// helper().runBootInterfaces();
@@ -149,11 +155,11 @@
private ClientResponse builtClientResponseWithIP (String collectionQuery,
- String ip) {
+ String ip) throws UniformInterfaceException, ClientHandlerException, KustvaktException {
return resource().path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp").queryParam("cq", collectionQuery)
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, ip)
.get(ClientResponse.class);
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
index 733f60d..2c1d3fe 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/UserServiceTest.java
@@ -18,14 +18,16 @@
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.nimbusds.jwt.SignedJWT;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.core.util.MultivaluedMapImpl;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.JWTSigner;
import de.ids_mannheim.korap.config.TestHelper;
@@ -45,6 +47,9 @@
@Ignore
public class UserServiceTest extends FastJerseyTest {
+ @Autowired
+ HttpAuthorizationHandler handler;
+
private static String[] credentials;
@Override
@@ -79,7 +84,7 @@
// map.putSingle("address", "Mannheim");
- String enc = BasicHttpAuth.encode("testuser", "testPassword1234");
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser", "testPassword1234");
response = resource().path("user").path("info")
.header("Content-Type", MediaType.APPLICATION_JSON).header(Attributes.AUTHORIZATION, enc)
.get(ClientResponse.class);
@@ -89,7 +94,7 @@
// test if user locked and what error message you get back
@Test
- public void testregisterWithoutConfirm() {
+ public void testregisterWithoutConfirm() throws KustvaktException {
MultivaluedMap map = new MultivaluedMapImpl();
map.putSingle("username", "testuser2");
map.putSingle("email", "hanl@ids-mannheim.de");
@@ -104,7 +109,7 @@
// run login/ status --> exception or information about locked account
// should appear
- String enc = BasicHttpAuth.encode("testuser2", "testPassword1234");
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser2", "testPassword1234");
response = resource().path("user").path("info").header(Attributes.AUTHORIZATION, enc)
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
@@ -137,15 +142,15 @@
response = resource().uri(URI.create(conf_uri)).get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
- String enc = BasicHttpAuth.encode("testuser", "testPassword1234");
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"testuser", "testPassword1234");
response = resource().path("user").path("info").header(Attributes.AUTHORIZATION, enc)
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void loginHTTP() {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ public void loginHTTP() throws KustvaktException {
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
ClientResponse response = resource().path("user").path("info")
.header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
@@ -155,7 +160,7 @@
@Test
@Ignore
public void loginJWT() throws KustvaktException{
- String en = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String en = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
/* lauffähige Version von Hanl: */
ClientResponse response = resource().path("auth").path("apiToken")
.header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
@@ -185,7 +190,7 @@
assertTrue(BeansFactory.getKustvaktContext().getConfiguration().getTokenTTL() < 10);
- String en = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String en = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
ClientResponse response = resource().path("auth").path("apiToken")
.header(Attributes.AUTHORIZATION, en).get(ClientResponse.class);
@@ -212,16 +217,16 @@
}
@Test
- public void testGetUserDetails() {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ public void testGetUserDetails() throws KustvaktException {
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
ClientResponse response = resource().path("user").path("details")
.header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void testGetUserDetailsEmbeddedPointer() {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ public void testGetUserDetailsEmbeddedPointer() throws KustvaktException {
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
Map m = new LinkedMap();
m.put("test", "[100, \"error message\", true, \"another message\"]");
@@ -239,7 +244,7 @@
@Test
public void testUpdateUserDetailsMerge() throws KustvaktException{
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
Map m = new LinkedMap();
m.put("test", "test value 1");
@@ -260,8 +265,8 @@
}
@Test
- public void testGetUserDetailsPointer() {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ public void testGetUserDetailsPointer() throws KustvaktException {
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
ClientResponse response = resource().path("user").path("details")
.queryParam("pointer", "email").header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
@@ -273,7 +278,7 @@
public void testGetUserDetailsNonExistent() throws KustvaktException {
helper().setupSimpleAccount("userservicetest", "servicepass");
- String enc = BasicHttpAuth.encode("userservicetest", "servicepass");
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,"userservicetest", "servicepass");
ClientResponse response = resource().path("user").path("details")
.header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -286,8 +291,8 @@
}
@Test
- public void testGetUserSettings() {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ public void testGetUserSettings() throws KustvaktException {
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
ClientResponse response = resource().path("user").path("settings")
.header(Attributes.AUTHORIZATION, enc).get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
@@ -295,7 +300,7 @@
@Test
public void testUpdateUserDetailsJson() throws KustvaktException{
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
Map m = new LinkedMap();
m.put("firstName", "newName");
m.put("lastName", "newLastName");
@@ -330,13 +335,13 @@
@Test
@Ignore
public void testUpdateUserSettingsForm() throws IOException, KustvaktException{
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
MultivaluedMap m = new MultivaluedMapImpl();
m.putSingle("queryLanguage", "poliqarp_test");
m.putSingle("pageLength", "200");
ClientResponse response = resource().path("user").path("settings")
- .header(Attributes.AUTHORIZATION, enc).header("Content-Type", "application/x-www-form-urlencoded")
+ .header(Attributes.AUTHORIZATION, enc).header("Content-Type", "application/x-www-form-urlencodeBase64d")
.get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
@@ -350,11 +355,11 @@
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", "application/x-www-form-urlencoded").post(ClientResponse.class, m);
+ .header("Content-Type", "application/x-www-form-urlencodeBase64d").post(ClientResponse.class, m);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
response = resource().path("user").path("settings").header(Attributes.AUTHORIZATION, enc)
- .header("Content-Type", "application/x-www-form-urlencoded").get(ClientResponse.class);
+ .header("Content-Type", "application/x-www-form-urlencodeBase64d").get(ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
map = JsonUtils.readTree(response.getEntity(String.class));
@@ -368,7 +373,7 @@
@Test
public void testUpdateUserSettingsJson() throws IOException, KustvaktException {
- String enc = BasicHttpAuth.encode(credentials[0], credentials[1]);
+ String enc = handler.createAuthorizationHeader(AuthenticationType.BASIC,credentials[0], credentials[1]);
Map m = new HashMap<>();
m.put("queryLanguage", "poliqarp_test");
m.put("pageLength", "200");
@@ -410,7 +415,7 @@
final String CREDENTIALS_INVALID = "{\"username\":\"testuser2\","
+ "\"email\":\"hanl@ids-mannheim.de\",\"password\":\"testpassword\"}";
// Response response = given()
- // .contentType("application/x-www-form-urlencoded").when()
+ // .contentType("application/x-www-form-urlencodeBase64d").when()
// .body(CREDENTIALS_INVALID).post("/register");
// String body = response.getBody().asString();
// Assert.assertEquals("response is in error", true,
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
index e115d7c..1a26e1c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
@@ -6,19 +6,24 @@
import org.eclipse.jetty.http.HttpHeaders;
import org.junit.Ignore;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.ClientResponse;
-import de.ids_mannheim.korap.authentication.BasicHttpAuth;
+import de.ids_mannheim.korap.authentication.framework.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.AuthenticationType;
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
public class VirtualCorpusServiceTest extends SpringJerseyTest{
-
+
+ @Autowired
+ HttpAuthorizationHandler handler;
+
@Test
@Ignore
public void testStoreVC () throws KustvaktException {
@@ -28,7 +33,7 @@
ClientResponse response = resource().path("vc").path("store")
.header(Attributes.AUTHORIZATION,
- BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ handler.createAuthorizationHeader(AuthenticationType.BASIC,"kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.entity(json)
.post(ClientResponse.class);
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index 7b85090..1ca00b0 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -209,7 +209,7 @@
type="de.ids_mannheim.korap.interfaces.db.PersistenceClient" ref="kustvakt_db" />
</bean>
- <bean id="basic_auth" class="de.ids_mannheim.korap.authentication.BasicHttpAuth" />
+ <bean id="basic_auth" class="de.ids_mannheim.korap.authentication.BasicAuthentication" />
<bean id="session_auth"