Checkpoint

This commit is contained in:
Filip Izydorczyk 2020-12-29 19:01:09 +01:00
parent 9f1e21a29f
commit ccb0161609
3 changed files with 122 additions and 0 deletions

View File

@ -74,6 +74,37 @@
<version>2.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.social/spring-social-core -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -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<ClientHttpRequestInterceptor> interceptors = new
// LinkedList<ClientHttpRequestInterceptor>();
// interceptors.add(interceptor);
// client.setInterceptors(interceptors);
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> result = xddd.exchange("https://usosapidemo.amu.edu.pl/services/users/user",
HttpMethod.GET, entity, String.class);
System.out.println(result);
}
}

View File

@ -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();
}
}