Updated OAuth2 client authentication.
Change-Id: Ic13a38afd2d405fa2b450d80c4737261a4ab1edc
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
index e54f354..6251147 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
@@ -7,6 +7,7 @@
import javax.ws.rs.core.MultivaluedMap;
import org.apache.http.entity.ContentType;
+import org.apache.oltu.oauth2.common.error.OAuthError;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,10 @@
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.input.OAuth2ClientJson;
+/**
+ * @author margaretha
+ *
+ */
public class OAuth2ClientControllerTest extends SpringJerseyTest {
@Autowired
@@ -40,7 +45,7 @@
json.setName("OAuth2ClientTest");
json.setType(OAuth2ClientType.CONFIDENTIAL);
json.setUrl("http://example.client.com");
- json.setRedirectURI("http://example.client.com/redirect");
+ json.setRedirectURI("https://example.client.com/redirect");
return resource().path("oauth2").path("client").path("register")
.header(Attributes.AUTHORIZATION,
@@ -79,7 +84,7 @@
json.setName("OAuth2PublicClient");
json.setType(OAuth2ClientType.PUBLIC);
json.setUrl("http://public.client.com");
- json.setRedirectURI("http://public.client.com/redirect");
+ json.setRedirectURI("https://public.client.com/redirect");
ClientResponse response = resource().path("oauth2").path("client")
.path("register")
@@ -155,13 +160,14 @@
ContentType.APPLICATION_FORM_URLENCODED)
.entity(form).delete(ClientResponse.class);
- assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
-
String entity = response.getEntity(String.class);
+// System.out.println(entity);
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
+
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHENTICATION_FAILED,
- node.at("/errors/0/0").asInt());
- assertEquals("Client credentials are incorrect.",
- node.at("/errors/0/1").asText());
+ assertEquals(OAuthError.TokenResponse.INVALID_CLIENT,
+ node.at("/error").asText());
+ assertEquals("Invalid client credentials.",
+ node.at("/error_description").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
new file mode 100644
index 0000000..f52c883
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
@@ -0,0 +1,53 @@
+package de.ids_mannheim.korap.web.controller;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.http.entity.ContentType;
+import org.apache.oltu.oauth2.common.message.types.GrantType;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.common.net.HttpHeaders;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+
+/**
+ * @author margaretha
+ *
+ */
+public class OAuth2ControllerTest extends SpringJerseyTest {
+
+ @Autowired
+ private HttpAuthorizationHandler handler;
+ private String username = "OAuth2ControllerTest";
+
+ @Test
+ public void testRequestTokenUnsupportedGrant ()
+ throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+// form.add("grant_type", "blahblah");
+ form.add("grant_type", GrantType.REFRESH_TOKEN.name());
+
+ ClientResponse response = resource().path("oauth2").path("token")
+ .header(Attributes.AUTHORIZATION,
+ handler.createBasicAuthorizationHeaderValue(username,
+ "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .entity(form).post(ClientResponse.class);
+
+ System.out.println(response.getStatus());
+ System.out.println(response.getEntity(String.class));
+ }
+
+}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
index 0653e69..af9f4ff 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
@@ -26,6 +26,10 @@
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.input.UserGroupJson;
+/**
+ * @author margaretha
+ *
+ */
public class UserGroupControllerAdminTest extends SpringJerseyTest {
@Autowired
private HttpAuthorizationHandler handler;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index 373d194..5da4c40 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -26,6 +26,10 @@
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.input.UserGroupJson;
+/**
+ * @author margaretha
+ *
+ */
public class UserGroupControllerTest extends SpringJerseyTest {
@Autowired
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
index 2b98f0d..28ed689 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
@@ -24,6 +24,10 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
+/**
+ * @author margaretha
+ *
+ */
public class VirtualCorpusControllerAdminTest extends SpringJerseyTest {
@Autowired
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index b01a164..71b1162 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -37,6 +37,10 @@
import de.ids_mannheim.korap.service.VirtualCorpusServiceTest;
import de.ids_mannheim.korap.utils.JsonUtils;
+/**
+ * @author margaretha
+ *
+ */
public class VirtualCorpusControllerTest extends SpringJerseyTest {
@Autowired
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index 562c3bb..1757481 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -169,6 +169,9 @@
<bean id="urlValidator" class="org.apache.commons.validator.routines.UrlValidator">
<constructor-arg value="http,https"/>
</bean>
+ <bean id="httpsValidator" class="org.apache.commons.validator.routines.UrlValidator">
+ <constructor-arg value="https"/>
+ </bean>
<bean id="kustvakt_rewrite" class="de.ids_mannheim.korap.rewrite.FullRewriteHandler">
<constructor-arg ref="kustvakt_config" />