Search in sources :

Example 1 with PendingResourceOwner

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

the class UserUtility method enterActivationCode.

public static ResponseEntity<DefaultOAuth2AccessToken> enterActivationCode(User user, String registerToken, PendingResourceOwner pendingResourceOwner) {
    HttpHeaders headers1 = new HttpHeaders();
    headers1.setContentType(MediaType.APPLICATION_JSON);
    headers1.setBearerAuth(registerToken);
    headers1.set("changeId", UUID.randomUUID().toString());
    pendingResourceOwner.setPassword(user.getPassword());
    pendingResourceOwner.setActivationCode("123456");
    HttpEntity<PendingResourceOwner> request1 = new HttpEntity<>(pendingResourceOwner, headers1);
    return TestContext.getRestTemplate().exchange(UrlUtility.getAccessUrl("/users"), HttpMethod.POST, request1, DefaultOAuth2AccessToken.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) PendingResourceOwner(com.hw.helper.PendingResourceOwner) HttpEntity(org.springframework.http.HttpEntity)

Example 2 with PendingResourceOwner

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

the class UserUtility method createPendingUser.

public static ResponseEntity<Void> createPendingUser(User user, String registerToken, PendingResourceOwner pendingResourceOwner) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setBearerAuth(registerToken);
    headers.set("changeId", UUID.randomUUID().toString());
    pendingResourceOwner.setEmail(user.getEmail());
    pendingResourceOwner.setMobileNumber(user.getMobileNumber());
    pendingResourceOwner.setCountryCode(user.getCountryCode());
    HttpEntity<PendingResourceOwner> request = new HttpEntity<>(pendingResourceOwner, headers);
    return TestContext.getRestTemplate().exchange(UrlUtility.getAccessUrl("/pending-users"), HttpMethod.POST, request, Void.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) PendingResourceOwner(com.hw.helper.PendingResourceOwner) HttpEntity(org.springframework.http.HttpEntity)

Example 3 with PendingResourceOwner

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

the class UserApiSecurityTest method should_not_able_to_create_user_w_client_missing_right_role.

@Test
public void should_not_able_to_create_user_w_client_missing_right_role() {
    User user = UserUtility.createUser();
    ResponseEntity<DefaultOAuth2AccessToken> registerTokenResponse = OAuth2Utility.getOAuth2ClientCredentialToken(CLIENT_ID_RIGHT_ROLE_NOT_SUFFICIENT_RESOURCE_ID, EMPTY_CLIENT_SECRET);
    String value = registerTokenResponse.getBody().getValue();
    ResponseEntity<Void> pendingUser = UserUtility.createPendingUser(user, value, new PendingResourceOwner());
    Assert.assertEquals(HttpStatus.FORBIDDEN, pendingUser.getStatusCode());
}
Also used : PendingResourceOwner(com.hw.helper.PendingResourceOwner) User(com.hw.helper.User) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PendingResourceOwner

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

the class UserUtility method register.

public static ResponseEntity<DefaultOAuth2AccessToken> register(User user) {
    ResponseEntity<DefaultOAuth2AccessToken> registerTokenResponse = OAuth2Utility.getOAuth2ClientCredentialToken(CLIENT_ID_REGISTER_ID, EMPTY_CLIENT_SECRET);
    PendingResourceOwner pendingResourceOwner = new PendingResourceOwner();
    createPendingUser(user, registerTokenResponse.getBody().getValue(), pendingResourceOwner);
    return enterActivationCode(user, registerTokenResponse.getBody().getValue(), pendingResourceOwner);
}
Also used : PendingResourceOwner(com.hw.helper.PendingResourceOwner) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)

Example 5 with PendingResourceOwner

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

the class BizUserApiSecurityTest method should_not_able_to_create_user_w_client_missing_right_role.

@Test
public void should_not_able_to_create_user_w_client_missing_right_role() throws JsonProcessingException {
    ResourceOwner user = action.randomCreateUserDraft();
    ResponseEntity<DefaultOAuth2AccessToken> registerTokenResponse = action.getJwtClientCredential(CLIENT_ID_RIGHT_ROLE_NOT_SUFFICIENT_RESOURCE_ID, EMPTY_CLIENT_SECRET);
    String value = registerTokenResponse.getBody().getValue();
    ResponseEntity<Void> pendingUser = action.createPendingUser(user, value, new PendingResourceOwner());
    Assert.assertEquals(HttpStatus.FORBIDDEN, pendingUser.getStatusCode());
}
Also used : PendingResourceOwner(com.hw.helper.PendingResourceOwner) PendingResourceOwner(com.hw.helper.PendingResourceOwner) ResourceOwner(com.hw.helper.ResourceOwner) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PendingResourceOwner (com.hw.helper.PendingResourceOwner)5 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)3 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResourceOwner (com.hw.helper.ResourceOwner)1 User (com.hw.helper.User)1