diff --git a/BackEnd/pom.xml b/BackEnd/pom.xml
index 89ab3c0..9c2eff9 100644
--- a/BackEnd/pom.xml
+++ b/BackEnd/pom.xml
@@ -29,7 +29,34 @@
commons-text
1.8
+
+ io.rest-assured
+ spring-mock-mvc
+ 3.1.1
+ test
+
+
+
+ org.json
+ json
+ 20190722
+
+
+ io.rest-assured
+ json-path
+ 3.1.1
+
+
+ io.rest-assured
+ rest-assured
+
+
+ io.rest-assured
+ rest-assured
+ 3.1.1
+ test
+
org.springframework.boot
@@ -90,6 +117,10 @@
+
+ io.rest-assured
+ rest-assured
+
diff --git a/BackEnd/src/main/java/studycave/studycaverestservice/PropertiesLoader.java b/BackEnd/src/main/java/studycave/studycaverestservice/PropertiesLoader.java
new file mode 100644
index 0000000..b6c1ec6
--- /dev/null
+++ b/BackEnd/src/main/java/studycave/studycaverestservice/PropertiesLoader.java
@@ -0,0 +1,43 @@
+package studycave.studycaverestservice;
+
+import io.restassured.RestAssured;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PropertiesLoader {
+
+ @Value("${usos.baseURI}")
+ private String usosBaseURI;
+
+ @Value("${usos.basePath}")
+ private String usosBasePath;
+
+ @Value("${usos.port}")
+ private int usosPort;
+
+ @Value("${application.key}")
+ private String key;
+
+ @Value("${application.secret}")
+ private String secret;
+
+ public void initUsosInstance() {
+ RestAssured.baseURI = usosBaseURI;
+ RestAssured.basePath = usosBasePath;
+ RestAssured.port = usosPort;
+ }
+
+ public String getUsosApiURL() {
+ return usosBaseURI + usosBasePath;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+}
diff --git a/BackEnd/src/main/java/studycave/studycaverestservice/StudycaveRestServiceApplication.java b/BackEnd/src/main/java/studycave/studycaverestservice/StudycaveRestServiceApplication.java
index a9a12d3..fa141d5 100644
--- a/BackEnd/src/main/java/studycave/studycaverestservice/StudycaveRestServiceApplication.java
+++ b/BackEnd/src/main/java/studycave/studycaverestservice/StudycaveRestServiceApplication.java
@@ -1,14 +1,20 @@
package studycave.studycaverestservice;
import org.modelmapper.ModelMapper;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import javax.annotation.PostConstruct;
+
@SpringBootApplication
public class StudycaveRestServiceApplication {
+ @Autowired
+ private PropertiesLoader propertiesLoader;
+
public static void main(String[] args) {
SpringApplication.run(StudycaveRestServiceApplication.class, args);
}
@@ -23,4 +29,9 @@ public class StudycaveRestServiceApplication {
return new ModelMapper();
}
+ @PostConstruct
+ private void LoadData() {
+ propertiesLoader.initUsosInstance();
+ }
+
}
diff --git a/BackEnd/src/main/java/studycave/studycaverestservice/controller/UsosController.java b/BackEnd/src/main/java/studycave/studycaverestservice/controller/UsosController.java
new file mode 100644
index 0000000..68e3f82
--- /dev/null
+++ b/BackEnd/src/main/java/studycave/studycaverestservice/controller/UsosController.java
@@ -0,0 +1,79 @@
+package studycave.studycaverestservice.controller;
+
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import studycave.studycaverestservice.PropertiesLoader;
+import studycave.studycaverestservice.model.user.User;
+import studycave.studycaverestservice.usos.AuthorizationService;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+@RestController
+@RequestMapping("/usos")
+public class UsosController {
+
+ private static final String ENC = "UTF-8";
+ @Autowired
+ private AuthorizationService authorizationService;
+ @Autowired
+ private PropertiesLoader propertiesLoader;
+
+ @GetMapping("/access_token")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "oauth_token", value = "User's oauth_token", required = true, dataType = "string", paramType = "header"),
+ @ApiImplicitParam(name = "oauth_token_secret", value = "User's oauth_token_secret", required = true, dataType = "string", paramType = "header"),
+ @ApiImplicitParam(name = "oauth_verifier", value = "User's oauth_verifier", required = true, dataType = "string", paramType = "header")
+ })
+ public ResponseEntity authorize(HttpServletRequest request) {
+ HttpHeaders responseHeaders = new HttpHeaders();
+
+ String oauth_token = request.getHeader("oauth_token");
+ String oauth_token_secret = request.getHeader("oauth_token_secret");
+ String oauth_verifier = request.getHeader("oauth_verifier");
+
+ try {
+ return ResponseEntity.status(HttpStatus.OK).headers(responseHeaders).body(authorizationService.authorize(oauth_token, oauth_token_secret, oauth_verifier));
+ } catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(responseHeaders).body(e.getCause().toString());
+ }
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "oauth_token", value = "User's oauth_token", required = true, dataType = "string", paramType = "header"),
+ @ApiImplicitParam(name = "oauth_token_secret", value = "User's oauth_token_secret", required = true, dataType = "string", paramType = "header")
+ })
+ @GetMapping("/details")
+ public ResponseEntity