Updated OAuth2 API responses for coherence.

Change-Id: If8cb86997f3e44083a4c899293e2e2d569247ead
diff --git a/full/Changes b/full/Changes
index b12efed..0a27f6d 100644
--- a/full/Changes
+++ b/full/Changes
@@ -16,7 +16,7 @@
  - Updated OAuth2 Client list (margaretha)
 2021-04-30
  - Updated parameters in the error responses of OAuth2 APIs for coherence (margaretha)
- 
+ - Updated OAuth2 API responses for coherence (margaretha) 
  
 # version 0.63
 26/10/2020
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2ClientInfoDto.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2ClientInfoDto.java
index 018cf38..fed37cd 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2ClientInfoDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2ClientInfoDto.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.oauth2.dto;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 
 import de.ids_mannheim.korap.oauth2.constant.OAuth2ClientType;
@@ -17,8 +18,10 @@
     private String id;
     private String name;
     private String description;
+    @JsonProperty("is_super")
     private String isSuper;
     private String url;
+    @JsonProperty("registered_by")
     private String registeredBy;
     private OAuth2ClientType type;
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2TokenDto.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2TokenDto.java
index ef2cbfc..6afb4ca 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2TokenDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2TokenDto.java
@@ -2,6 +2,8 @@
 
 import java.util.Set;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 /**
  * Describes OAuth2 refresh tokens
  * 
@@ -11,14 +13,21 @@
 public class OAuth2TokenDto {
 
     private String token;
+    @JsonProperty("created_date")
     private String createdDate;
-    private String expiryDate;
+    @JsonProperty("expires_in")
+    private long expiresIn;
+    @JsonProperty("user_authentication_time")
     private String userAuthenticationTime;
-    private Set<String> scopes;
+    private Set<String> scope;
 
+    @JsonProperty("client_id")
     private String clientId;
+    @JsonProperty("client_name")
     private String clientName;
+    @JsonProperty("client_description")
     private String clientDescription;
+    @JsonProperty("client_url")
     private String clientUrl;
 
     public String getToken () {
@@ -69,12 +78,12 @@
         this.createdDate = createdDate;
     }
 
-    public String getExpiryDate () {
-        return expiryDate;
+    public long getExpiresIn () {
+        return expiresIn;
     }
 
-    public void setExpiryDate (String expiryDate) {
-        this.expiryDate = expiryDate;
+    public void setExpiresIn (long expiresIn) {
+        this.expiresIn = expiresIn;
     }
 
     public String getUserAuthenticationTime () {
@@ -86,12 +95,12 @@
         this.userAuthenticationTime = userAuthenticationTime;
     }
 
-    public Set<String> getScopes () {
-        return scopes;
+    public Set<String> getScope () {
+        return scope;
     }
 
-    public void setScopes (Set<String> scopes) {
-        this.scopes = scopes;
+    public void setScope (Set<String> scope) {
+        this.scope = scope;
     }
 
 }
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2UserClientDto.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2UserClientDto.java
index 23916f2..8c8d39d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2UserClientDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/dto/OAuth2UserClientDto.java
@@ -1,5 +1,7 @@
 package de.ids_mannheim.korap.oauth2.dto;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+
 import de.ids_mannheim.korap.oauth2.constant.OAuth2ClientType;
 
 /** Lists authorized OAuth2 clients of a user
@@ -8,9 +10,11 @@
  *
  */
 public class OAuth2UserClientDto {
-    
+    @JsonProperty("client_id")
     private String clientId;
+    @JsonProperty("client_name")
     private String clientName;
+    @JsonProperty("client_type")
     private OAuth2ClientType clientType;
     private String description;
     private String url;
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuTokenService.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuTokenService.java
index d066063..4d63e75 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuTokenService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/oltu/service/OltuTokenService.java
@@ -3,6 +3,7 @@
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -39,6 +40,7 @@
 import de.ids_mannheim.korap.oauth2.oltu.OAuth2RevokeTokenSuperRequest;
 import de.ids_mannheim.korap.oauth2.service.OAuth2ClientService;
 import de.ids_mannheim.korap.oauth2.service.OAuth2TokenService;
+import de.ids_mannheim.korap.utils.TimeUtils;
 
 /** Implementation of token service using Apache Oltu.
  * 
@@ -537,7 +539,9 @@
             
             DateTimeFormatter f = DateTimeFormatter.ISO_DATE_TIME;
             dto.setCreatedDate(t.getCreatedDate().format(f));
-            dto.setExpiryDate(t.getExpiryDate().format(f));
+            long difference = ChronoUnit.SECONDS.between(ZonedDateTime.now(), t.getExpiryDate());
+            dto.setExpiresIn(difference);
+            
             dto.setUserAuthenticationTime(
                     t.getUserAuthenticationTime().format(f));
             dto.setToken(t.getToken());
@@ -547,7 +551,7 @@
             for (AccessScope s : accessScopes){
                 scopes.add(s.getId().toString());
             }
-            dto.setScopes(scopes);
+            dto.setScope(scopes);
             dtoList.add(dto);
         }
         return dtoList;
@@ -579,7 +583,10 @@
             
             DateTimeFormatter f = DateTimeFormatter.ISO_DATE_TIME;
             dto.setCreatedDate(t.getCreatedDate().format(f));
-            dto.setExpiryDate(t.getExpiryDate().format(f));
+            
+            long difference = ChronoUnit.SECONDS.between(ZonedDateTime.now(), t.getExpiryDate());
+            dto.setExpiresIn(difference);
+                    
             dto.setUserAuthenticationTime(
                     t.getUserAuthenticationTime().format(f));
             dto.setToken(t.getToken());
@@ -589,7 +596,7 @@
             for (AccessScope s : accessScopes){
                 scopes.add(s.getId().toString());
             }
-            dto.setScopes(scopes);
+            dto.setScope(scopes);
             dtoList.add(dto);
         }
         return dtoList;
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
index e043837..bdc4b18 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
@@ -349,7 +349,7 @@
     @ResourceFilters({ AuthenticationFilter.class, BlockingFilter.class })
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-    public List<OAuth2TokenDto> listUserRefreshToken (
+    public List<OAuth2TokenDto> listUserToken (
             @Context SecurityContext context,
             @FormParam("super_client_id") String superClientId,
             @FormParam("super_client_secret") String superClientSecret,
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 ac94979..e5acd73 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
@@ -110,13 +110,14 @@
         assertNotNull(clientInfo.at("/description"));
         assertNotNull(clientInfo.at("/url"));
         assertEquals("PUBLIC", clientInfo.at("/type").asText());
+        assertEquals("system", clientInfo.at("/registered_by").asText());
 
         // confidential client
         clientInfo = retrieveClientInfo(confidentialClientId, "system");
         assertEquals(confidentialClientId, clientInfo.at("/id").asText());
         assertEquals("non super confidential client", clientInfo.at("/name").asText());
         assertNotNull(clientInfo.at("/url"));
-        assertEquals(false,clientInfo.at("/isSuper").asBoolean());
+        assertEquals(false,clientInfo.at("/is_super").asBoolean());
         assertEquals("CONFIDENTIAL", clientInfo.at("/type").asText());
         
         // super client
@@ -125,7 +126,7 @@
         assertEquals("super confidential client", clientInfo.at("/name").asText());
         assertNotNull(clientInfo.at("/url"));
         assertEquals("CONFIDENTIAL", clientInfo.at("/type").asText());
-        assertTrue(clientInfo.at("/isSuper").asBoolean());
+        assertTrue(clientInfo.at("/is_super").asBoolean());
     }
     
     @Test
@@ -466,7 +467,7 @@
 
         updateClientPrivilege(form);
         JsonNode node = retrieveClientInfo(clientId, "admin");
-        assertTrue(node.at("/isSuper").asBoolean());
+        assertTrue(node.at("/is_super").asBoolean());
 
         // list vc
         ClientResponse response = resource().path(API_VERSION).path("vc")
@@ -528,8 +529,8 @@
         String entity = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(entity);
         assertEquals(2, node.size());
-        assertEquals(confidentialClientId, node.at("/0/clientId").asText());
-        assertEquals(publicClientId, node.at("/1/clientId").asText());
+        assertEquals(confidentialClientId, node.at("/0/client_id").asText());
+        assertEquals(publicClientId, node.at("/1/client_id").asText());
     }
 
     @Test
@@ -703,9 +704,9 @@
         JsonNode node = JsonUtils.readTree(entity);
         
         assertEquals(1, node.size());
-        assertEquals(clientName, node.at("/0/clientName").asText());
-        assertEquals(OAuth2ClientType.PUBLIC.name(), node.at("/0/clientType").asText());
-        String clientId = node.at("/0/clientId").asText();
+        assertEquals(clientName, node.at("/0/client_name").asText());
+        assertEquals(OAuth2ClientType.PUBLIC.name(), node.at("/0/client_type").asText());
+        String clientId = node.at("/0/client_id").asText();
         testDeregisterPublicClient(clientId, "dory");
     }
 }
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
index 3b1a187..22a8abd 100644
--- 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
@@ -739,8 +739,8 @@
         // list
         node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE);
         assertEquals(2, node.size());
-        assertEquals(confidentialClientId, node.at("/0/clientId").asText());
-        assertEquals(confidentialClientId2, node.at("/1/clientId").asText());
+        assertEquals(confidentialClientId, node.at("/0/client_id").asText());
+        assertEquals(confidentialClientId2, node.at("/1/client_id").asText());
 
         // client 1
         code = requestAuthorizationCode(confidentialClientId, clientSecret,
@@ -837,7 +837,19 @@
         
         testRevokeTokenViaSuperClient(accessToken1, userAuthHeader);
         node = requestTokenList(userAuthHeader, ACCESS_TOKEN_TYPE);
+        System.out.println(node);
         assertEquals(1, node.size());
+        assertEquals(accessToken2, node.at("/0/token").asText());
+        assertTrue(node.at("/0/scope").size()>0);
+        assertNotNull(node.at("/0/created_date").asText());
+        assertNotNull(node.at("/0/expires_in").asLong());
+        assertNotNull(node.at("/0/user_authentication_time").asText());
+        
+        assertEquals(publicClientId, node.at("/0/client_id").asText());
+        assertNotNull(node.at("/0/client_name").asText());
+        assertNotNull(node.at("/0/client_description").asText());
+        assertNotNull(node.at("/0/client_url").asText());
+        
         
         testRevokeTokenViaSuperClient(accessToken2, userAuthHeader);
         node = requestTokenList(userAuthHeader, ACCESS_TOKEN_TYPE);