From ccb01616095f8f085f3ae87e56a59bf10dc3ae58 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 29 Dec 2020 19:01:09 +0100 Subject: [PATCH] Checkpoint --- buisnesslogic/pom.xml | 31 +++++++++++ .../plannaplan/services/UsosApiService.java | 54 +++++++++++++++++++ .../services/UsosApiServiceTest.java | 37 +++++++++++++ 3 files changed, 122 insertions(+) create mode 100755 buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java create mode 100755 buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java diff --git a/buisnesslogic/pom.xml b/buisnesslogic/pom.xml index 7ac501b..cc76da2 100755 --- a/buisnesslogic/pom.xml +++ b/buisnesslogic/pom.xml @@ -74,6 +74,37 @@ 2.2.5.RELEASE + + + org.springframework.social + spring-social-core + 1.1.6.RELEASE + + + + org.springframework.social + spring-social-web + 1.1.6.RELEASE + + + + org.springframework.social + spring-social-config + 1.1.6.RELEASE + + + + org.springframework.social + spring-social-security + 1.1.6.RELEASE + + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java b/buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java new file mode 100755 index 0000000..1f5eb25 --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java @@ -0,0 +1,54 @@ +package com.plannaplan.services; + +import java.util.LinkedList; +import java.util.List; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.social.oauth1.OAuth1Parameters; +import org.springframework.social.support.ClientHttpRequestFactorySelector; +// import org.springframework.social.oauth1.OAuth1Template; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.social.oauth1.*; +import org.springframework.http.client.ClientHttpRequestInterceptor; +// import org.springframework.social.oauth1.ProtectedResourceClientFactory; + +@Service +public class UsosApiService { + public UsosApiService() { + + } + + public void xd() { + RestTemplate xddd = new RestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + headers.set("oauth_version", "1.0"); + headers.set("oauth_signature_method", "HMAC-SHA1"); + headers.set("oauth_consumer_key", "e6jbeN57HC99MfsfmZwN"); + headers.set("oauth_signature", "fhcLdwerJyzZBGA9WnAYzbySJRW9Wv5wj3h8uVgp"); + headers.set("oauth_nonce", "" + (int) (Math.random() * 100000000)); + headers.set("oauth_timestamp", "" + (System.currentTimeMillis() / 1000)); + + // BasicAuthenticationInterceptor + + // OAuth1Credentials credentials; + // RestTemplate client = new + // RestTemplate(ClientHttpRequestFactorySelector.getRequestFactory()); + // OAuth1RequestInterceptor interceptor = new + // OAuth1RequestInterceptor(credentials); + // List interceptors = new + // LinkedList(); + // interceptors.add(interceptor); + // client.setInterceptors(interceptors); + + HttpEntity entity = new HttpEntity<>(headers); + + ResponseEntity result = xddd.exchange("https://usosapidemo.amu.edu.pl/services/users/user", + HttpMethod.GET, entity, String.class); + System.out.println(result); + } +} diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java new file mode 100755 index 0000000..6167e9a --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java @@ -0,0 +1,37 @@ +package com.plannaplan.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.MethodMode; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import com.plannaplan.entities.User; +import com.plannaplan.exceptions.UserNotFoundException; +import com.plannaplan.types.UserRoles; + +import org.junit.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.runner.RunWith; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ContextConfiguration +@TestMethodOrder(OrderAnnotation.class) +public class UsosApiServiceTest { + + @Autowired + private UsosApiService service; + + @Test + public void chuj() { + this.service.xd(); + } + +}