Search in sources :

Example 1 with OAuthAuthenticationException

use of org.eclipse.che.security.oauth1.OAuthAuthenticationException in project che-server by eclipse-che.

the class HttpBitbucketServerApiClientTest method start.

@BeforeMethod
void start() {
    wireMockServer = new WireMockServer(wireMockConfig().notifier(new Slf4jNotifier(false)).dynamicPort());
    wireMockServer.start();
    WireMock.configureFor("localhost", wireMockServer.port());
    wireMock = new WireMock("localhost", wireMockServer.port());
    bitbucketServer = new HttpBitbucketServerApiClient(wireMockServer.url("/"), new BitbucketServerOAuthAuthenticator("", "", "", "") {

        @Override
        public String computeAuthorizationHeader(String userId, String requestMethod, String requestUrl) throws OAuthAuthenticationException {
            return AUTHORIZATION_TOKEN;
        }
    });
}
Also used : BitbucketServerOAuthAuthenticator(org.eclipse.che.security.oauth1.BitbucketServerOAuthAuthenticator) HttpBitbucketServerApiClient(org.eclipse.che.api.factory.server.bitbucket.server.HttpBitbucketServerApiClient) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) WireMock(com.github.tomakehurst.wiremock.client.WireMock) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with OAuthAuthenticationException

use of org.eclipse.che.security.oauth1.OAuthAuthenticationException in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClientTest method start.

@BeforeMethod
void start() {
    wireMockServer = new WireMockServer(wireMockConfig().notifier(new Slf4jNotifier(false)).dynamicPort());
    wireMockServer.start();
    WireMock.configureFor("localhost", wireMockServer.port());
    wireMock = new WireMock("localhost", wireMockServer.port());
    bitbucketServer = new HttpBitbucketServerApiClient(wireMockServer.url("/"), new BitbucketServerOAuthAuthenticator("", "", "", "") {

        @Override
        public String computeAuthorizationHeader(String userId, String requestMethod, String requestUrl) throws OAuthAuthenticationException {
            return AUTHORIZATION_TOKEN;
        }
    });
}
Also used : BitbucketServerOAuthAuthenticator(org.eclipse.che.security.oauth1.BitbucketServerOAuthAuthenticator) HttpBitbucketServerApiClient(org.eclipse.che.api.factory.server.bitbucket.server.HttpBitbucketServerApiClient) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) WireMock(com.github.tomakehurst.wiremock.client.WireMock) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with OAuthAuthenticationException

use of org.eclipse.che.security.oauth1.OAuthAuthenticationException in project che-server by eclipse-che.

the class HttpBitbucketServerApiClient method computeAuthorizationHeader.

private String computeAuthorizationHeader(String requestMethod, String requestUrl) throws ScmUnauthorizedException, ScmCommunicationException {
    try {
        Subject subject = EnvironmentContext.getCurrent().getSubject();
        String authorizationHeader = authenticator.computeAuthorizationHeader(subject.getUserId(), requestMethod, requestUrl);
        if (Strings.isNullOrEmpty(authorizationHeader)) {
            throw buildScmUnauthorizedException();
        }
        return authorizationHeader;
    } catch (OAuthAuthenticationException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : OAuthAuthenticationException(org.eclipse.che.security.oauth1.OAuthAuthenticationException) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Subject(org.eclipse.che.commons.subject.Subject)

Example 4 with OAuthAuthenticationException

use of org.eclipse.che.security.oauth1.OAuthAuthenticationException in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClient method computeAuthorizationHeader.

private String computeAuthorizationHeader(String requestMethod, String requestUrl) throws ScmUnauthorizedException, ScmCommunicationException {
    try {
        Subject subject = EnvironmentContext.getCurrent().getSubject();
        String authorizationHeader = authenticator.computeAuthorizationHeader(subject.getUserId(), requestMethod, requestUrl);
        if (Strings.isNullOrEmpty(authorizationHeader)) {
            throw buildScmUnauthorizedException();
        }
        return authorizationHeader;
    } catch (OAuthAuthenticationException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : OAuthAuthenticationException(org.eclipse.che.security.oauth1.OAuthAuthenticationException) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 Slf4jNotifier (com.github.tomakehurst.wiremock.common.Slf4jNotifier)2 HttpBitbucketServerApiClient (org.eclipse.che.api.factory.server.bitbucket.server.HttpBitbucketServerApiClient)2 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)2 Subject (org.eclipse.che.commons.subject.Subject)2 BitbucketServerOAuthAuthenticator (org.eclipse.che.security.oauth1.BitbucketServerOAuthAuthenticator)2 OAuthAuthenticationException (org.eclipse.che.security.oauth1.OAuthAuthenticationException)2 BeforeMethod (org.testng.annotations.BeforeMethod)2