use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class UserLinksInjector method injectLinks.
public UserDto injectLinks(UserDto userDto, ServiceContext serviceContext) {
final UriBuilder uriBuilder = serviceContext.getBaseUriBuilder();
final List<Link> links = new ArrayList<>(6);
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getById").build(userDto.getId()).toString(), null, APPLICATION_JSON, LINK_REL_SELF));
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getCurrent").build().toString(), null, APPLICATION_JSON, LINK_REL_CURRENT_USER));
links.add(LinksHelper.createLink(HttpMethod.POST, uriBuilder.clone().path(UserService.class).path(UserService.class, "updatePassword").build().toString(), APPLICATION_FORM_URLENCODED, null, LINK_REL_CURRENT_USER_PASSWORD));
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(ProfileService.class).path(ProfileService.class, "getById").build(userDto.getId()).toString(), null, APPLICATION_JSON, LINK_REL_PROFILE));
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(UserService.class).path(UserService.class, "getSettings").build().toString(), null, APPLICATION_JSON, LINK_REL_CURRENT_USER_SETTINGS));
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(PreferencesService.class).path(PreferencesService.class, "find").build().toString(), null, APPLICATION_JSON, LINK_REL_PREFERENCES));
return userDto.withLinks(links);
}
use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class SshService method injectLinks.
private SshPairDto injectLinks(SshPairDto sshPairDto) {
final UriBuilder uriBuilder = getServiceContext().getServiceUriBuilder();
final Link getPairsLink = LinksHelper.createLink("GET", uriBuilder.clone().path(getClass(), "getPairs").build(sshPairDto.getService()).toString(), APPLICATION_JSON, LINK_REL_GET_PAIR);
final Link removePairLink = LinksHelper.createLink("DELETE", uriBuilder.clone().path(getClass(), "removePair").build(sshPairDto.getService(), sshPairDto.getName()).toString(), APPLICATION_JSON, LINK_REL_REMOVE_PAIR);
final Link getPairLink = LinksHelper.createLink("GET", uriBuilder.clone().path(getClass(), "getPair").build(sshPairDto.getService(), sshPairDto.getName()).toString(), APPLICATION_JSON, LINK_REL_GET_PAIR);
return sshPairDto.withLinks(Arrays.asList(getPairsLink, removePairLink, getPairLink));
}
use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class MachineItemTest method shouldReturnTerminalUrl.
@Test
public void shouldReturnTerminalUrl() {
String terminalHref = "terminalHref";
Link someLink = mock(Link.class);
Link terminalLink = mock(Link.class);
List<Link> links = new ArrayList<>(2);
links.add(someLink);
links.add(terminalLink);
when(terminalLink.getHref()).thenReturn(terminalHref);
when(terminalLink.getRel()).thenReturn(TERMINAL_REFERENCE);
when(descriptor.getLinks()).thenReturn(links);
machine = new MachineItem(descriptor);
String terminalUrl = machine.getTerminalUrl();
assertEquals(terminalHref, terminalUrl);
}
use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class OAuthAuthenticationService method getRegisteredAuthenticators.
/**
* Gets list of installed OAuth authenticators.
*
* @return list of installed OAuth authenticators
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Set<OAuthAuthenticatorDescriptor> getRegisteredAuthenticators() {
Set<OAuthAuthenticatorDescriptor> result = new HashSet<>();
final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder().clone().path(getClass());
for (String name : providers.getRegisteredProviderNames()) {
final List<Link> links = new LinkedList<>();
links.add(LinksHelper.createLink(HttpMethod.GET, uriBuilder.clone().path(getClass(), "authenticate").build().toString(), null, null, "Authenticate URL", newDto(LinkParameter.class).withName("oauth_provider").withRequired(true).withDefaultValue(name), newDto(LinkParameter.class).withName("mode").withRequired(true).withDefaultValue("federated_login")));
result.add(newDto(OAuthAuthenticatorDescriptor.class).withName(name).withLinks(links));
}
return result;
}
use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.
the class RemoteOAuthTokenProvider method getToken.
/** {@inheritDoc} */
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
if (userId.isEmpty()) {
return null;
}
try {
UriBuilder ub = UriBuilder.fromUri(apiEndpoint).path(OAuthAuthenticationService.class).path(OAuthAuthenticationService.class, "token").queryParam("oauth_provider", oauthProviderName);
Link getTokenLink = DtoFactory.newDto(Link.class).withHref(ub.build().toString()).withMethod("GET");
return httpJsonRequestFactory.fromLink(getTokenLink).request().asDto(OAuthToken.class);
} catch (NotFoundException ne) {
LOG.warn("Token not found for user {}", userId);
return null;
} catch (ServerException | UnauthorizedException | ForbiddenException | ConflictException | BadRequestException e) {
LOG.warn("Exception on token retrieval, message : {}", e.getLocalizedMessage());
return null;
}
}
Aggregations