Search in sources :

Example 1 with AuthToken

use of org.eclipse.openvsx.entities.AuthToken in project openvsx by eclipse.

the class EclipseService method revokePublisherAgreement.

/**
 * Revoke the given user's publisher agreement. If an admin user is given,
 * the admin's access token is used for the Eclipse API request, otherwise
 * the access token of the target user is used.
 */
public void revokePublisherAgreement(UserData user, UserData admin) {
    checkApiUrl();
    AuthToken eclipseToken;
    if (admin == null)
        eclipseToken = checkEclipseToken(user);
    else
        eclipseToken = checkEclipseToken(admin);
    var headers = new HttpHeaders();
    headers.setBearerAuth(eclipseToken.accessToken);
    var request = new HttpEntity<Void>(headers);
    var eclipseData = checkEclipseData(user);
    var requestUrl = UrlUtil.createApiUrl(eclipseApiUrl, "openvsx", "publisher_agreement", eclipseData.personId);
    try {
        var requestCallback = restTemplate.httpEntityCallback(request);
        restTemplate.execute(requestUrl, HttpMethod.DELETE, requestCallback, null);
        if (eclipseData.publisherAgreement != null) {
            updateEclipseData(user, ed -> {
                ed.publisherAgreement.isActive = false;
                return null;
            }, NOP_INIT);
        }
    } catch (RestClientException exc) {
        logger.error("Delete request failed with URL: " + requestUrl, exc);
        throw new ErrorResultException("Request for revoking publisher agreement failed: " + exc.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) RestClientException(org.springframework.web.client.RestClientException) AuthToken(org.eclipse.openvsx.entities.AuthToken)

Example 2 with AuthToken

use of org.eclipse.openvsx.entities.AuthToken in project openvsx by eclipse.

the class EclipseServiceTest method testRevokePublisherAgreementByAdmin.

@Test
public void testRevokePublisherAgreementByAdmin() throws Exception {
    var user = mockUser();
    var eclipseData = new EclipseData();
    user.setEclipseData(eclipseData);
    eclipseData.personId = "test";
    eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
    eclipseData.publisherAgreement.isActive = true;
    var admin = new UserData();
    admin.setLoginName("admin");
    admin.setEclipseToken(new AuthToken());
    admin.getEclipseToken().accessToken = "67890";
    Mockito.when(tokens.getActiveToken(admin, "eclipse")).thenReturn(admin.getEclipseToken());
    eclipse.revokePublisherAgreement(user, admin);
    assertThat(user.getEclipseData().publisherAgreement.isActive).isFalse();
}
Also used : UserData(org.eclipse.openvsx.entities.UserData) AuthToken(org.eclipse.openvsx.entities.AuthToken) EclipseData(org.eclipse.openvsx.entities.EclipseData) Test(org.junit.jupiter.api.Test)

Example 3 with AuthToken

use of org.eclipse.openvsx.entities.AuthToken in project openvsx by eclipse.

the class EclipseServiceTest method mockUser.

private UserData mockUser() {
    var user = new UserData();
    user.setLoginName("test");
    user.setEclipseToken(new AuthToken());
    user.getEclipseToken().accessToken = "12345";
    Mockito.when(tokens.getActiveToken(user, "eclipse")).thenReturn(user.getEclipseToken());
    return user;
}
Also used : UserData(org.eclipse.openvsx.entities.UserData) AuthToken(org.eclipse.openvsx.entities.AuthToken)

Aggregations

AuthToken (org.eclipse.openvsx.entities.AuthToken)3 UserData (org.eclipse.openvsx.entities.UserData)2 EclipseData (org.eclipse.openvsx.entities.EclipseData)1 ErrorResultException (org.eclipse.openvsx.util.ErrorResultException)1 Test (org.junit.jupiter.api.Test)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestClientException (org.springframework.web.client.RestClientException)1