@Bean public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor("admin", "123456"); }
/** * Creates an interceptor that authenticates all requests with the specified username and password * encoded using the specified charset. * * @param username the username to use for authentication * @param password the password to use for authentication * @param charset the charset to use when encoding the credentials */ public BasicAuthRequestInterceptor(String username, String password, Charset charset) { checkNotNull(username, "username"); checkNotNull(password, "password"); this.headerValue = "Basic " + base64Encode((username + ":" + password).getBytes(charset)); }
/** * Creates an instance of BasicAuth interceptor configured with a username and password. This bean is only created if the * "direct.webservices.security.basic.user.name" property is set. * @return An instance of BasicAuth interceptor configured with a username and password */ @Bean @ConditionalOnProperty(name="direct.webservices.security.basic.user.name", matchIfMissing=false) public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor(user, pass); }
@Bean @ConditionalOnProperty(name = { "feign.client.github.username", "feign.client.github.password" }) public BasicAuthRequestInterceptor basicAuthRequestInterceptor( @Value("${feign.client.github.username}") String githubUsername, @Value("${feign.client.github.password}") String githubPassword) { return new BasicAuthRequestInterceptor(githubUsername, githubPassword); } }
@Bean @ConditionalOnProperty(name = { "feign.client.azrael.username", "feign.client.azrael.password" }) public BasicAuthRequestInterceptor basicAuthRequestInterceptor( @Value("${feign.client.azrael.username}") final String azraelUsername, @Value("${feign.client.azrael.password}") final String azraelPassword) { return new BasicAuthRequestInterceptor(azraelUsername, azraelPassword); }
/** * 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)); }
/** * Creates a Marathon client proxy that performs HTTP basic authentication. * @param endpoint URL of Marathon * @param username marathon account username * @param password marathon account password for the given username * @return A {@link Marathon} instance that uses the given basic auth scheme */ public static Marathon getInstanceWithBasicAuth(String endpoint, String username, String password) { return getInstance(endpoint,new BasicAuthRequestInterceptor(username,password)); }
/** * 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)); }
@Bean @ConditionalOnProperty(value = "io.fundrequest.mock.identity-api", havingValue = "false", matchIfMissing = true) public IdentityAPIClient identityAPIClient(final Decoder decoder, final Encoder encoder, final Client identityApiFeignClient, final Contract contract, @Value("${io.fundrequest.identity.api.url}") final String url, @Value("${io.fundrequest.identity.api.user.name}") final String username, @Value("${io.fundrequest.identity.api.user.password}") final String password) { return Feign.builder() .client(identityApiFeignClient) .encoder(encoder) .decoder(decoder) .contract(contract) .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .target(IdentityAPIClient.class, url); }
@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/"); }
@Override public void signIn() { final Feign.Builder builder = Feign.builder() .logger(new Slf4jLogger()) .decoder(new GsonDecoder()); if(this.etcdUsername != null && this.etcdPassword != null) { builder.requestInterceptor( new BasicAuthRequestInterceptor(this.etcdUsername, this.etcdPassword)); } this.etcdService = builder.target(EtcdService.class, this.etcdEnpoint); }
public AuthStatus getAuthenticatedUser() { BasicAuthRequestInterceptor interceptor = new BasicAuthRequestInterceptor(USERNAME, PASSWORD); HttpBinResource bookResource = Feign.builder().encoder(new JacksonEncoder()) .decoder(new JacksonDecoder()).requestInterceptor(interceptor) .target(HttpBinResource.class, HTTP_BIN_URL); return bookResource.getAuthenticatedUser(); }
@Override public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException { BusinessProcessApi api = Feign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder()) //.errorDecoder(new WorkflowErrorDecoder()) .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .target(BusinessProcessApi.class, serviceEndpoint); ProcessInstanceData instanceData = null; try { instanceData = api.getProcessInstances(workflowExtRef); } catch (WorkflowExtensionException e) { throw new WorkflowException("WorkflowException: " + e.getMessage(), e); } // should be only one process instance for this business key, hence get the 0th element try { if (instanceData.getData().size() != 0) { api.deleteProcessInstance(Integer.toString(instanceData.getData().get(0).getId())); } } catch (WorkflowExtensionException e) { throw new WorkflowException("WorkflowException: " + e.getMessage(), e); } log.info("Application Creation approval process instance task with business key " + workflowExtRef + " deleted successfully"); }
.decoder(new JacksonDecoder()) .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .target(BusinessProcessApi.class, serviceEndpoint);
public <T> T build(String username, String password, int connectTimeoutMillis, int readTimeoutMillis, Class<T> target, String url) { return Feign.builder().requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .encoder(new Encoder.Default()).decoder(new Decoder.Default()) .options(new Request.Options(connectTimeoutMillis, readTimeoutMillis)) .client(newDefaultClientInstance()) .target(target, url); }
new BasicAuthRequestInterceptor(username, password)) .target(BusinessProcessApi.class, serviceEndpoint);
.decoder(new JacksonDecoder()) .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .target(BusinessProcessApi.class, serviceEndpoint);
/** * Create and return OAuth2 Introspection service stubs * * @return OAuth2 introspection service stub * @throws APIManagementException if error occurs while crating OAuth2 introspection service stub */ public OAuth2ServiceStubs.IntrospectionServiceStub getIntrospectionServiceStub() throws APIManagementException { return Feign.builder() .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .encoder(new FormEncoder()) .decoder(new GsonDecoder()) .client(new Client.Default(AMSSLSocketFactory.getSSLSocketFactory(kmCertAlias), (hostname, sslSession) -> true)) .target(OAuth2ServiceStubs.IntrospectionServiceStub.class, introspectEndpoint); } /**
/** * Create and return OAuth2 Introspection service stubs * * @return OAuth2 introspection service stub * @throws APIManagementException if error occurs while crating OAuth2 introspection service stub */ public OAuth2ServiceStubs.IntrospectionServiceStub getIntrospectionServiceStub() throws APIManagementException { return Feign.builder() .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .encoder(new FormEncoder()) .decoder(new GsonDecoder()) .client(new Client.Default(AMSSLSocketFactory.getSSLSocketFactory(kmCertAlias), (hostname, sslSession) -> true)) .target(OAuth2ServiceStubs.IntrospectionServiceStub.class, introspectEndpoint); } /**
/** * Create and return SCIM service stubs * * @param idpBaseUrl Base URL of Identity Provider Server * @param username Username of IDP * @param password Password of IDP * @param idpCertAlias Alias of Public Key of IDP * @return SCIM Service client * @throws APIManagementException if error occurs while crating SCIM service stub */ public static SCIMServiceStub getSCIMServiceStub(String idpBaseUrl, String username, String password, String idpCertAlias) throws APIManagementException { return Feign.builder() .requestInterceptor(new BasicAuthRequestInterceptor(username, password)) .encoder(new GsonEncoder()) .decoder(new GsonDecoder()) .client(new Client.Default(AMSSLSocketFactory.getSSLSocketFactory(idpCertAlias), (hostname, sslSession) -> true)) .target(SCIMServiceStub.class, idpBaseUrl + WSO2_SCIM_BASE_PATH); }