Search in sources :

Example 31 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method getClientAsResource.

public static Client getClientAsResource(String... resourceIds) {
    Client client = getClientRaw(resourceIds);
    client.setResourceIndicator(true);
    Set<ClientType> strings = new HashSet<>();
    strings.add(ClientType.BACKEND_APP);
    strings.add(ClientType.FIRST_PARTY);
    client.setTypes(strings);
    return client;
}
Also used : ClientType(com.hw.helper.ClientType) Client(com.hw.helper.Client) HashSet(java.util.HashSet)

Example 32 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method createClient.

public static ResponseEntity<String> createClient(Client client, String changeId) {
    ResponseEntity<DefaultOAuth2AccessToken> jwtPasswordAdmin = UserUtility.getJwtPasswordAdmin();
    String bearer = jwtPasswordAdmin.getBody().getValue();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setBearerAuth(bearer);
    headers.set("changeId", changeId);
    headers.set("X-XSRF-TOKEN", "123");
    headers.add(HttpHeaders.COOKIE, "XSRF-TOKEN=123");
    HttpEntity<Client> request = new HttpEntity<>(client, headers);
    return TestContext.getRestTemplate().exchange(CLIENT_MNGMT_URL, HttpMethod.POST, request, String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Client(com.hw.helper.Client) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 33 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method createClient.

public static ResponseEntity<String> createClient(Client client) {
    ResponseEntity<DefaultOAuth2AccessToken> jwtPasswordAdmin = UserUtility.getJwtPasswordAdmin();
    String bearer = jwtPasswordAdmin.getBody().getValue();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setBearerAuth(bearer);
    HttpEntity<Client> request = new HttpEntity<>(client, headers);
    return TestContext.getRestTemplate().exchange(CLIENT_MNGMT_URL, HttpMethod.POST, request, String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Client(com.hw.helper.Client) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 34 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method getClientAsNonResource.

/**
 * get client as non resource.
 *
 * @return different GRANT_TYPE_PASSWORD client obj
 */
public static Client getClientAsNonResource(String... resourceIds) {
    Client client = getClientRaw(resourceIds);
    client.setResourceIndicator(false);
    Set<ClientType> types = new HashSet<>();
    types.add(ClientType.BACKEND_APP);
    types.add(ClientType.FIRST_PARTY);
    client.setTypes(types);
    return client;
}
Also used : ClientType(com.hw.helper.ClientType) Client(com.hw.helper.Client) HashSet(java.util.HashSet)

Example 35 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class BizClientIdempotentTest method create_client_w_same_changeId_two_times.

@Test
public void create_client_w_same_changeId_two_times() {
    Client oldClient = action.getClientAsResource(CLIENT_ID_RESOURCE_ID);
    String s = UUID.randomUUID().toString();
    ResponseEntity<String> client1 = action.createClient(oldClient, s);
    Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
    ResponseEntity<String> client2 = action.createClient(oldClient, s);
    Assert.assertEquals(HttpStatus.OK, client2.getStatusCode());
}
Also used : Client(com.hw.helper.Client) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Client (com.hw.helper.Client)36 Test (org.junit.Test)30 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)23 HttpEntity (org.springframework.http.HttpEntity)18 HttpHeaders (org.springframework.http.HttpHeaders)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 GrantTypeEnum (com.hw.helper.GrantTypeEnum)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 MultiValueMap (org.springframework.util.MultiValueMap)4 ClientType (com.hw.helper.ClientType)3 SumTotal (com.hw.helper.SumTotal)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ResponseEntity (org.springframework.http.ResponseEntity)3 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 Map (java.util.Map)1 Ignore (org.junit.Ignore)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1