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