当前位置: 首页>>代码示例>>Java>>正文


Java HttpAuthenticationFeature.basic方法代码示例

本文整理汇总了Java中org.glassfish.jersey.client.authentication.HttpAuthenticationFeature.basic方法的典型用法代码示例。如果您正苦于以下问题:Java HttpAuthenticationFeature.basic方法的具体用法?Java HttpAuthenticationFeature.basic怎么用?Java HttpAuthenticationFeature.basic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.jersey.client.authentication.HttpAuthenticationFeature的用法示例。


在下文中一共展示了HttpAuthenticationFeature.basic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLdapAuthentication

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
@Test
public void testLdapAuthentication(){
  String userInfoURI = sdcURL  + "/rest/v1/system/info/currentUser";
  HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);
  Response response = ClientBuilder
      .newClient()
      .register(feature)
      .target(userInfoURI)
      .request()
      .get();

  if (!result) {
    Assert.assertEquals(401, response.getStatus());
  } else{
    Assert.assertEquals(200, response.getStatus());
    Map userInfo = response.readEntity(Map.class);
    Assert.assertTrue(userInfo.containsKey("user"));
    Assert.assertEquals(username, userInfo.get("user"));
    Assert.assertTrue(userInfo.containsKey("roles"));
    List<String> roles = (List<String>) userInfo.get("roles");
    Assert.assertEquals(role.size(), roles.size());
    for(int i = 0; i < roles.size(); i++) {
      Assert.assertEquals(role.get(i), roles.get(i));
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:LDAPAuthenticationFallbackIT.java

示例2: testCORSGetRequest

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
private void testCORSGetRequest(String userInfoURI) throws Exception {
  HttpAuthenticationFeature authenticationFeature = HttpAuthenticationFeature.basic("admin", "admin");
  Response response = ClientBuilder.newClient()
      .target(userInfoURI)
      .register(authenticationFeature)
      .request()
      .header("Origin", "http://example.com")
      .header("Access-Control-Request-Method", "GET")
      .get();

  Assert.assertEquals(200, response.getStatus());

  MultivaluedMap<String, Object> responseHeader = response.getHeaders();

  List<Object> allowOriginHeader = responseHeader.get(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER);
  Assert.assertNotNull(allowOriginHeader);
  Assert.assertEquals(1, allowOriginHeader.size());
  Assert.assertEquals("http://example.com", allowOriginHeader.get(0));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:TestHttpAccessControl.java

示例3: assertAuthenticationSuccess

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * Assert authentication result using ldap-login.conf with given username and password.
 * All user for this test is configured so that role "admin" will be found and successfully authenticated.
 * @param ldapConf  The configuration for ldap-login.conf
 * @param username  username to login
 * @param password  password to login
 * @throws Exception
 */
public static void assertAuthenticationSuccess(String ldapConf, String username, String password) throws Exception{
  startSDCServer(ldapConf);

  String userInfoURI = sdcURL  + "/rest/v1/system/info/currentUser";
  HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);
  Response response = ClientBuilder
      .newClient()
      .register(feature)
      .target(userInfoURI)
      .request()
      .get();

  Assert.assertEquals(200, response.getStatus());
  Map userInfo = response.readEntity(Map.class);
  Assert.assertTrue(userInfo.containsKey("user"));
  Assert.assertEquals(username, userInfo.get("user"));
  Assert.assertTrue(userInfo.containsKey("roles"));
  Assert.assertEquals(1, ((List)userInfo.get("roles")).size());
  Assert.assertEquals("admin", ((List)userInfo.get("roles")).get(0));
  stopSDCServer();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:30,代码来源:LdapAuthenticationIT.java

示例4: register

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * Registers a service by it's specified information within {@code this} service registry.
 * <p />
 * The specified http client will be used to call the service registry.
 * <p />
 * Exceptions will be logged and won't be exposed by this method.
 *
 * @param serviceInformation the information of the service to register
 * @param client the http client
 */
public boolean register(final ServiceInformation serviceInformation, final Client client) {
    try {
        final HttpAuthenticationFeature authenticationFeature = HttpAuthenticationFeature.basic(credentials.getUsername(), credentials.getPassword());
        final Response response = client.register(authenticationFeature).target(baseUrl).path("/services").request()
                .buildPost(Entity.json(serviceInformation)).invoke();
        if (!response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
            log.warn("failed to register service with response: {} (code: {})", response, response.getStatus());
            throw new ProcessingException("invalid registry response code: " + response.getStatus());
        }
        log.info("successfully registered service \"{}\"", serviceInformation.getName());
        return true;
    } catch (final ProcessingException e) {
        log.warn("failed to register service \"" + serviceInformation.getName() + "\"");
        return false;
    }
}
 
开发者ID:bitionaire,项目名称:el-bombillo,代码行数:27,代码来源:RegistryService.java

示例5: createRESTClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * By default, the app creates an insecure client for REST activity 
 * with PingOne.  Meaning, the app does not do any SSL/TLS certificate
 * checking to ensure the PingOne cert is presented.  
 * 
 * WARNING:  You should never put insecure code like this into production.
 * For production, replace this function, and use a keystore that
 * contains the PingOne certificate.
 * 
 * @param config
 * @param logger
 * @return an inscecure client for REST activity.
 */
private Client createRESTClient(SSOConfig config, Logger logger) {
	
	// Use local routines to establish an insecure REST client
	// that connects to any server.  These routines should NEVER
	// be used in a production app!
	SSLContext ctx = getSSLContext("TLS");
	HostnameVerifier hnv = getHostnameVerifier();
	
	// Create a Jersey client instance that uses TLS (HTTPS)
	Client client = ClientBuilder.newBuilder()
			.sslContext(ctx).hostnameVerifier(hnv).build();
	HttpAuthenticationFeature basicAuth = HttpAuthenticationFeature.basic(ssoConfig.getClientId(),ssoConfig.getClientSecret());
	// If HTTP Basic Auth credentials were provided in the config,
	// then set up the BasicAuth filter
	if (ssoConfig.getClientId() != null && ssoConfig.getClientSecret() != null) {
		client.register(basicAuth);
	}
	
	// Register the logger so we can watch the traffic between
	// PingOne and our app
	//client.register(JacksonFeature.class).register(new LoggingFilter(logger, true));
	
	return client;
}
 
开发者ID:dskyberg-Ping,项目名称:pingone-app,代码行数:38,代码来源:SSOManager.java

示例6: OneTimeSecretRestImpl

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
public OneTimeSecretRestImpl(
        final String url,
        final String username,
        final String apiToken) {
    if (StringUtils.isBlank(url)) {
        throw new IllegalArgumentException("One Time Secret url must be set");
    }
    if (StringUtils.isBlank(username)) {
        throw new IllegalArgumentException("One Time Secret username must be set");
    }
    if (StringUtils.isBlank(apiToken)) {
        throw new IllegalArgumentException("One Time Secret api token must be set");
    }
    this.url = url;
    authFeature = HttpAuthenticationFeature.basic(username, apiToken);
}
 
开发者ID:mpawlowski,项目名称:onetime-java,代码行数:17,代码来源:OneTimeSecretRestImpl.java

示例7: acquireClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * Acquire a {@link Client} and bind it to the current thread.
 * <p>
 * <b>Important: You must {@linkplain #releaseClient() release} the client!</b> Use a try/finally block!
 * @see #releaseClient()
 * @see #getClientOrFail()
 */
private synchronized void acquireClient(){
	final ClientRef clientRef = clientThreadLocal.get();
	if (clientRef != null) {
		++clientRef.refCount;
		return;
	}

	Client client = clientCache.poll();
	if (client == null) {
		client = clientBuilder.build();

		// An authentication is always required. Otherwise Jersey throws an exception.
		// Hence, we set it to "anonymous" here and set it to the real values for those
		// requests really requiring it.
		final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("anonymous", "");
		client.register(feature);
	}
	clientThreadLocal.set(new ClientRef(client));
}
 
开发者ID:cloudstore,项目名称:cloudstore,代码行数:27,代码来源:CloudStoreRestClient.java

示例8: restClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * Build a Jersey http client instance
 *
 * @return Client
 */
@Bean
public Client restClient() {
    final ClientConfig cc = new ClientConfig().register(new JacksonFeature());
    final HttpAuthenticationFeature httpAuthenticationFeature = HttpAuthenticationFeature.basic(cloudKarafkaApiKey, "");

    final Client client = ClientBuilder.newClient(cc);
    client.register(httpAuthenticationFeature);

    return client;
}
 
开发者ID:ipolyzos,项目名称:cloudkarafka-broker,代码行数:16,代码来源:BrokerConfig.java

示例9: main

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
 
     try {
         //Client client = Client.create();
         // Accept self-signed certificates
         Client client = createClient();

         String username = "user";
         String password = "password";
         //client.addFilter(new HTTPBasicAuthFilter(username, password));
         HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);
         client.register(feature);
         
         WebTarget webResource = client.target("https://localhost:8443");
         WebTarget webResourceWithPath = webResource.path("ss7fw_api/1.0/eval_sccp_message_in_ids");
         WebTarget webResourceWithQueryParam = webResourceWithPath.matrixParam("sccp_raw", "12345");
         
         System.out.println(webResourceWithQueryParam);
         
         //ClientResponse response = webResourceWithQueryParam.accept("text/plain").get(ClientResponse.class);
         Response response = webResourceWithQueryParam.request("text/plain").get();
         
         if (response.getStatus() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
         }

         String output = response.readEntity(String.class);

         System.out.println("Output from Server .... \n");
         System.out.println(output);

} catch (Exception e) {
           e.printStackTrace();
}
     
 }
 
开发者ID:P1sec,项目名称:SigFW,代码行数:37,代码来源:RestClientTest.java

示例10: addServer

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
public boolean addServer(String url, String username, String password) {
    Client client = createClient();
    serverList.add(client);

    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);
    client.register(feature);
    
    WebTarget target = client.target(url);
    serverTargetsList.add(target);
    
    return true;
}
 
开发者ID:P1sec,项目名称:SigFW,代码行数:13,代码来源:ConnectorMThreatModuleRest.java

示例11: addServer

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
/**
 * Add IDS server
 * 
 * @param url url address of IDS server
 * @param username username for IDS server
 * @param password password for IDS server
 * @return true if successful
 */
public boolean addServer(String url, String username, String password) {
    Client client = createClient();
    serverList.add(client);

    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password);
    client.register(feature);
    
    //WebTarget target = client.target(url).path("ss7fw_api/1.0/eval_sccp_message_in_ids");
    WebTarget target = client.target(url);
    serverTargetsList.add(target);
    
    return true;
}
 
开发者ID:P1sec,项目名称:SigFW,代码行数:22,代码来源:ConnectorIDSModuleRest.java

示例12: setUp

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
@BeforeClass
public void setUp() throws Exception {
    client = ClientBuilder.newClient();
    HttpAuthenticationFeature feature = HttpAuthenticationFeature
            .basic("[email protected]", "pass");
    client.register(feature);
    webTarget = client.target(BASE_URI);
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:9,代码来源:BaseResourceTest.java

示例13: initializeClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
private void initializeClient(String username, String password) {

        reentrantLock.lock();
        try {
            if (client != null)
                return;

            // build client
            ClientConfig clientConfig = new ConfigLoader<>(ClientConfig.class, "interfax-api-config.yaml").getTestConfig();
            HttpAuthenticationFeature httpAuthenticationFeature = HttpAuthenticationFeature.basic(username, password);
            client = ClientBuilder.newClient();
            client.register(httpAuthenticationFeature);
            client.register(MultiPartFeature.class);
            client.register(RequestEntityProcessing.CHUNKED);
            client.register(JacksonFeature.class);

            // required for the document upload API, to set Content-Length header
            System.setProperty("sun.net.http.allowRestrictedHeaders", "true");

            // for automatically deriving content type given a file
            tika = new Tika();

            // read config from yaml
            scheme = clientConfig.getInterFAX().getScheme();
            hostname = clientConfig.getInterFAX().getHostname();
            port = clientConfig.getInterFAX().getPort();
            readConfigAndInitializeEndpoints(clientConfig);
        } finally {
            reentrantLock.unlock();
        }
    }
 
开发者ID:interfax,项目名称:interfax-java,代码行数:32,代码来源:DefaultInterFAXClient.java

示例14: deletePackage

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
private boolean deletePackage() throws MojoFailureException, MojoExecutionException
{
    // Package name with tailing dot (.) character
    // Example: com.example.packagename.
    String packageName = o11nPackageName + ".";
    
    // Example: https://localhost:8281
    URI packageServiceBaseUri = UriBuilder.fromUri("https://" + o11nServer + ":" + o11nServicePort.toString()).build();
    HttpAuthenticationFeature packageServiceAuth = HttpAuthenticationFeature.basic(o11nPluginServiceUser, o11nPluginServicePassword);

    return deletePackage(packageServiceBaseUri, packageServiceAuth, packageName);
}
 
开发者ID:m451,项目名称:o11n-deploy-maven-plugin,代码行数:13,代码来源:DeployPlugin.java

示例15: uploadPlugin

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入方法依赖的package包/类
private boolean uploadPlugin() throws MojoFailureException, MojoExecutionException
{
    // Example: https://localhost:8281
    URI pluginServiceBaseUri = UriBuilder.fromUri("https://" + o11nServer + ":" + o11nServicePort.toString()).build();
    HttpAuthenticationFeature pluginServiceAuth = HttpAuthenticationFeature.basic(o11nPluginServiceUser, o11nPluginServicePassword);

    return uploadPlugin(pluginServiceBaseUri, pluginServiceAuth, o11nPluginType, String.valueOf(o11nOverwrite), file);
}
 
开发者ID:m451,项目名称:o11n-deploy-maven-plugin,代码行数:9,代码来源:DeployPlugin.java


注:本文中的org.glassfish.jersey.client.authentication.HttpAuthenticationFeature.basic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。