feign.auth.BasicAuthRequestInterceptor Java Examples

The following examples show how to use feign.auth.BasicAuthRequestInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlertsPublisher.java    From hawkular-apm with Apache License 2.0 7 votes vote down vote up
@Asynchronous
public void publish(final Event event) {
    if (BASE_URL == null || BASE_URL.isEmpty()) {
        logger.hawkularServerNotConfigured();
        return;
    }

    if (USERNAME == null || USERNAME.isEmpty()) {
        logger.hawkularServerUsernameNotConfigured();
        return;
    }

    if (PASSWORD == null || PASSWORD.isEmpty()) {
        logger.hawkularServerPasswordNotConfigured();
        return;
    }

    HystrixFeign.builder()
            .requestInterceptor(new BasicAuthRequestInterceptor(USERNAME, PASSWORD))
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .retryer(new Retryer.Default())
            .target(AlertsService.class, TARGET)
            .addEvent(event);
}
 
Example #2
Source File: GameClientResolver.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
private GameServerClient buildGameServerClient(String server) {
    return Feign.builder()
            .client(new OkHttpClient())
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .errorDecoder(new ClientErrorDecoder())
            .logger(new Slf4jLogger(GameServerClient.class))
            .logLevel(Level.BASIC)
            .requestInterceptor(new BasicAuthRequestInterceptor(gameProperties.getBasicAuthUser(),
                    Hash.md5(gameProperties.getBasicAuthPassword())))
            .target(GameServerClient.class, gameProperties.getSchema() + "://" + server);
}
 
Example #3
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
 static LinshareAPIForUserTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForUserTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForUserTesting.class, linshare.getUrl());
}
 
Example #4
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPIForTechnicalAccountTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForTechnicalAccountTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForTechnicalAccountTesting.class, linshare.getUrl());
}
 
Example #5
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPIForAdminTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForAdminTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForAdminTesting.class, linshare.getUrl());
}
 
Example #6
Source File: LinshareAPI.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPI from(LinshareConfiguration configuration) {
    return Feign.builder()
        .requestInterceptor(
            new BasicAuthRequestInterceptor(
                configuration.getUuid().toString(),
                configuration.getPassword()))
        .logger(new Slf4jLogger(LinshareAPI.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(new JacksonDecoder())
        .target(LinshareAPI.class, configuration.getUrl().toString());
}
 
Example #7
Source File: RabbitMQManagementAPI.java    From james-project with Apache License 2.0 5 votes vote down vote up
static RabbitMQManagementAPI from(RabbitMQConfiguration configuration) {
    RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
        .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new JacksonEncoder())
        .decoder(new JacksonDecoder())
        .retryer(new Retryer.Default())
        .errorDecoder(RETRY_500)
        .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
}
 
Example #8
Source File: OAuthRequestInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an interceptor that authenticates all requests.
 */
public OAuthRequestInterceptor() {
    String username = APIMConfigReader.getInstance().getConfig().getUsername();
    String password = APIMConfigReader.getInstance().getConfig().getPassword();
    dcrClient = Feign.builder().client(new OkHttpClient(Utils.getSSLClient())).logger(new Slf4jLogger())
            .logLevel(Logger.Level.FULL).requestInterceptor(new BasicAuthRequestInterceptor(username,
                    password))
            .contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
            .target(DCRClient.class, Utils.replaceProperties(
                    APIMConfigReader.getInstance().getConfig().getDcrEndpoint()));
}
 
Example #9
Source File: MovieController.java    From spring-cloud-docker-microservice-book-code with Apache License 2.0 5 votes vote down vote up
@Autowired
public MovieController(Decoder decoder, Encoder encoder, Client client, Contract contract) {
  // 这边的decoder、encoder、client、contract,可以debug看看是什么实例。
  this.userUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
      .requestInterceptor(new BasicAuthRequestInterceptor("user", "password1")).target(UserFeignClient.class, "http://microservice-provider-user/");
  this.adminUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
      .requestInterceptor(new BasicAuthRequestInterceptor("admin", "password2"))
      .target(UserFeignClient.class, "http://microservice-provider-user/");
}
 
Example #10
Source File: MovieController.java    From spring-cloud-docker-microservice-book-code with Apache License 2.0 5 votes vote down vote up
@Autowired
public MovieController(Decoder decoder, Encoder encoder, Client client, Contract contract) {
  // 这边的decoder、encoder、client、contract,可以debug看看是什么实例。
  this.userUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
      .requestInterceptor(new BasicAuthRequestInterceptor("user", "password1")).target(UserFeignClient.class, "http://microservice-provider-user/");
  this.adminUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
      .requestInterceptor(new BasicAuthRequestInterceptor("admin", "password2"))
      .target(UserFeignClient.class, "http://microservice-provider-user/");
}
 
Example #11
Source File: RibbonMarathonClient.java    From spring-cloud-marathon with MIT License 5 votes vote down vote up
public Marathon build() {
    if (null == listOfServers) {
        if (!StringUtils.isEmpty(token)) {
            return getInstanceWithTokenAuth(baseEndpoint, token);
        } else if (!StringUtils.isEmpty(username)) {
            return getInstanceWithBasicAuth(baseEndpoint, username, password);
        } else {
            return getInstance(baseEndpoint);
        }
    } else {
        setMarathonRibbonProperty("listOfServers", listOfServers);
        setMarathonRibbonProperty("OkToRetryOnAllOperations", Boolean.TRUE.toString());
        setMarathonRibbonProperty("MaxAutoRetriesNextServer", maxRetryCount);
        setMarathonRibbonProperty("ConnectTimeout", connectionTimeout);
        setMarathonRibbonProperty("ReadTimeout", readTimeout);

        Feign.Builder builder = Feign.builder()
                .client(RibbonClient.builder().lbClientFactory(new MarathonLBClientFactory()).build())
                .encoder(new GsonEncoder(ModelUtils.GSON))
                .decoder(new GsonDecoder(ModelUtils.GSON))
                .errorDecoder(new MarathonErrorDecoder());

        if (!StringUtils.isEmpty(token)) {
            builder.requestInterceptor(new TokenAuthRequestInterceptor(token));
        }
        else if (!StringUtils.isEmpty(username)) {
            builder.requestInterceptor(new BasicAuthRequestInterceptor(username,password));
        }

        builder.requestInterceptor(new MarathonHeadersInterceptor());

        return builder.target(Marathon.class, DEFAULT_MARATHON_ENDPOINT);
    }
}
 
Example #12
Source File: Application.java    From hawkbit-examples with Eclipse Public License 1.0 5 votes vote down vote up
private static MgmtSoftwareModuleClientResource uploadSoftwareModule(
        final ClientConfigurationProperties configuration) {
    final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jackson2HalModule());
    return Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract()).decode404()
            .requestInterceptor(
                    new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword()))
            .logger(new Slf4jLogger()).encoder(new FeignMultipartEncoder())
            .decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)))
            .target(MgmtSoftwareModuleClientResource.class, configuration.getUrl());
}
 
Example #13
Source File: ChronosClient.java    From spring-cloud-deployer-mesos with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Chronos client proxy that performs HTTP basic authentication.
 */
public static Chronos getInstanceWithBasicAuth(String endpoint, String username, String password) {
	return getInstance(endpoint, new BasicAuthRequestInterceptor(username, password));
}
 
Example #14
Source File: SmsGatewayClient.java    From codenjoy with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public RequestInterceptor basicAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor(smsProperties.getGateway().getUser(),
            smsProperties.getGateway().getPassword());
}
 
Example #15
Source File: Application.java    From hawkbit-examples with Eclipse Public License 1.0 4 votes vote down vote up
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor(final ClientConfigurationProperties configuration) {
    return new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword());
}
 
Example #16
Source File: MetronomeClient.java    From pravega with Apache License 2.0 4 votes vote down vote up
public static Metronome getInstanceWithBasicAuth(String endpoint, String username, String password) {
    return getInstance(endpoint, new BasicAuthRequestInterceptor(username, password));
}
 
Example #17
Source File: LoginClient.java    From pravega with Apache License 2.0 4 votes vote down vote up
public static RequestInterceptor getAuthenticationRequestInterceptor() {
    return new BasicAuthRequestInterceptor(getUsername(), getPassword());
}
 
Example #18
Source File: FeignConfiguration.java    From mogu_blog_v2 with Apache License 2.0 4 votes vote down vote up
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor("user", "password123");
}
 
Example #19
Source File: GossipApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor(
		@Value("${client.web.name}") String clientName, 
		@Value("${client.web.secret}") String clientSecret) {
     return new BasicAuthRequestInterceptor(clientName, clientSecret);
}
 
Example #20
Source File: AuthServiceConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public RequestInterceptor requestInterceptor(
		@Value("${client.web.name}") String clientName, 
		@Value("${client.web.secret}") String clientSecret) {
     return new BasicAuthRequestInterceptor(clientName, clientSecret);
}
 
Example #21
Source File: BasicAuthConfiguration.java    From NetworkDisk_Storage with GNU General Public License v2.0 4 votes vote down vote up
@Bean
public BasicAuthRequestInterceptor basicAuthorizationInterceptor() {
    return new BasicAuthRequestInterceptor("admin", "admin123");
}
 
Example #22
Source File: HttpBasicAuthConfig.java    From xmfcn-spring-cloud with Apache License 2.0 4 votes vote down vote up
/**
 * 访问base-service的用户名密码.
 *
 */
@Bean
public BasicAuthRequestInterceptor appServiceAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor(name, password);
}
 
Example #23
Source File: HttpBasicAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(RequestTemplate template) {
    RequestInterceptor requestInterceptor = new BasicAuthRequestInterceptor(username, password);
    requestInterceptor.apply(template);
}
 
Example #24
Source File: FeignClientOverrideDefaultsTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@Bean
RequestInterceptor feignRequestInterceptor() {
	return new BasicAuthRequestInterceptor("user", "pass");
}
 
Example #25
Source File: FeignConfig.java    From fw-spring-cloud with Apache License 2.0 4 votes vote down vote up
/**
 * 设置Spring Security Basic认证的用户名密码
 * @return
 */
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor(){
    return new BasicAuthRequestInterceptor("user","123456");
}
 
Example #26
Source File: FeignConfiguration.java    From mogu_blog_v2 with Apache License 2.0 4 votes vote down vote up
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor("user", "password123");
}
 
Example #27
Source File: MarathonClient.java    From marathon-client with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a Marathon client proxy that performs HTTP basic authentication.
 *
 * @param endpoint URL for Marathon
 * @param username basic auth username
 * @param password basic auth password
 * @return Marathon client
 */
public static Marathon getInstanceWithBasicAuth(String endpoint, String username, String password) {
	return getInstance(endpoint,new BasicAuthRequestInterceptor(username,password));
}