Search in sources :

Example 1 with HttpBasicAuth

use of org.wso2.carbon.apimgt.rest.integration.tests.store.auth.HttpBasicAuth in project product-apim by wso2.

the class ApiClient method setCredentials.

/**
 * Helper method to configure the username/password for basic auth or password OAuth
 *
 * @param username Username
 * @param password Password
 */
public void setCredentials(String username, String password) {
    for (RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
        if (apiAuthorization instanceof HttpBasicAuth) {
            HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
            basicAuth.setCredentials(username, password);
            return;
        }
        if (apiAuthorization instanceof OAuth) {
            OAuth oauth = (OAuth) apiAuthorization;
            oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
            return;
        }
    }
    throw new RuntimeException("No Basic authentication or OAuth configured!");
}
Also used : HttpBasicAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.HttpBasicAuth) RequestInterceptor(feign.RequestInterceptor) OAuth(org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)

Aggregations

RequestInterceptor (feign.RequestInterceptor)1 HttpBasicAuth (org.wso2.carbon.apimgt.rest.integration.tests.store.auth.HttpBasicAuth)1 OAuth (org.wso2.carbon.apimgt.rest.integration.tests.store.auth.OAuth)1