Search in sources :

Example 11 with UnauthorizedException

use of org.eclipse.che.api.core.UnauthorizedException 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;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Aggregations

UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)11 IOException (java.io.IOException)10 ServerException (org.eclipse.che.api.core.ServerException)8 ArrayList (java.util.ArrayList)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)3 File (java.io.File)3 HashMap (java.util.HashMap)3 BadRequestException (org.eclipse.che.api.core.BadRequestException)3 ConflictException (org.eclipse.che.api.core.ConflictException)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Files (com.google.common.io.Files)2 JSch (com.jcraft.jsch.JSch)2 Session (com.jcraft.jsch.Session)2 OutputStream (java.io.OutputStream)2 String.format (java.lang.String.format)2 Date (java.util.Date)2