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


Java HttpAuthenticationFeature类代码示例

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


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

示例1: Scim2Provisioner

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
public Scim2Provisioner(final String target, final String oauthToken,
                        final String username, final String password,
                        final Scim2PrincipalAttributeMapper mapper) {
    final ClientConfig config = new ClientConfig();
    final ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
    config.connectorProvider(connectorProvider);
    final Client client = ClientBuilder.newClient(config);
    
    if (StringUtils.isNotBlank(oauthToken)) {
        client.register(OAuth2ClientSupport.feature(oauthToken));
    }
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
        client.register(HttpAuthenticationFeature.basic(username, password));
    }
    
    final WebTarget webTarget = client.target(target);
    this.scimService = new ScimService(webTarget);
    this.mapper = mapper;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:Scim2Provisioner.java

示例2: getRegistryClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
private RegistryEndpoints getRegistryClient(ImageRef imageRef) {
	if (!proxyClients.containsKey(imageRef.getRegistryUrl())) {

		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(new JavaTimeModule());

		Client client = ClientBuilder.newClient()
				.register(new JacksonJaxbJsonProvider(mapper, new Annotations[] {Annotations.JACKSON}))
				.register(JacksonFeature.class);
		String auth = config.getAuthFor(imageRef.getRegistryName());
		if (auth != null) {
			String[] credentials = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8).split(":");
			client.register(HttpAuthenticationFeature.basicBuilder().credentials(credentials[0], credentials[1]));
		}
		WebTarget webTarget = client.target(imageRef.getRegistryUrl());
		proxyClients.put(imageRef.getRegistryUrl(), WebResourceFactory.newResource(RegistryEndpoints.class, webTarget));
	}
	return proxyClients.get(imageRef.getRegistryUrl());
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:20,代码来源:DockerRegistry.java

示例3: Session

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
public Session(Properties properties) {
    log.info("Initializing a new session with a specified properties file" );

    List<String> requiredProperties = new ArrayList<>(
            Arrays.asList("baseurl", "username", "password", "pemfile"));

    this.throwErrorOnRequiredProperty(properties, requiredProperties);

    String baseUrl  = properties.getProperty(requiredProperties.get(0));
    String username = properties.getProperty(requiredProperties.get(1));
    String password = properties.getProperty(requiredProperties.get(2));
    String pemFile  = properties.getProperty(requiredProperties.get(3));

    webTarget = ClientBuilder.newClient().target(baseUrl);

    if (sessionKey == null) {
        log.info("Session key was not set. Authenticate the client");
        login = Authenticate.login(webTarget, username, password, pemFile);
        sessionKey = login.getSessionKey();
    }
    webTarget = webTarget.register(HttpAuthenticationFeature.basic(sessionKey, sessionKey));
}
 
开发者ID:djonsson,项目名称:nordnet-next-api,代码行数:23,代码来源:Session.java

示例4: getHttpClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
Client getHttpClient() {
    if (httpClient == null) {
        try {
            SSLContext sslCtx = SSLContext.getInstance("SSL");
            TrustManager tm = new TrustThemAll();
            sslCtx.init(null, new TrustManager[] {tm}, null);

            httpClient = ClientBuilder.newBuilder()
                    .sslContext(sslCtx)
                    .register(HttpAuthenticationFeature.basic(user, passwd))
                    .build();
            httpClient.property(ClientProperties.FOLLOW_REDIRECTS, true);
            httpClient.property(ClientProperties.CONNECT_TIMEOUT, 2 * 60 * 1000); // 2 min
        } catch (NoSuchAlgorithmException | KeyManagementException ex) {
            throw new IllegalStateException(ex);
        }
    }
    return httpClient;
}
 
开发者ID:proarc,项目名称:proarc,代码行数:20,代码来源:ResolverClient.java

示例5: retrievePagedLinks

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
@Override
public IntegrationPaginatedResult<LinkDTO> retrievePagedLinks(final String site, final String container,
    final IntegrationPaginatedDataFilter filter,
    final String user,
    final String password) throws Exception {

    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("page", (filter.getOffset() / filter.getLimit()) + 1 );
    queryParams.put("pageSize", filter.getLimit());

    HashMap<String,Object> properties = null;
    if (user != null && password != null){
        properties = new HashMap<String,Object>();
        properties.put(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_USERNAME, user);
        properties.put(HttpAuthenticationFeature.HTTP_AUTHENTICATION_BASIC_PASSWORD, password);
    }
    return this.retrievePagedQuery(alfrescoRestClient.path("links/site/webtestsite/links"),
            filter, null, queryParams, properties);
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:20,代码来源:LinkRepositoryImpl.java

示例6: configurePasswordAuth

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
public static void configurePasswordAuth(
    AuthenticationType authType,
    String username,
    String password,
    ClientBuilder clientBuilder
) {
  if (authType == AuthenticationType.BASIC) {
    clientBuilder.register(HttpAuthenticationFeature.basic(username, password));
  }

  if (authType == AuthenticationType.DIGEST) {
    clientBuilder.register(HttpAuthenticationFeature.digest(username, password));
  }

  if (authType == AuthenticationType.UNIVERSAL) {
    clientBuilder.register(HttpAuthenticationFeature.universal(username, password));
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:JerseyClientUtil.java

示例7: configurePasswordAuth

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
private void configurePasswordAuth(WebhookCommonConfig webhookConfig, WebTarget webTarget) {
  if (webhookConfig.authType == AuthenticationType.BASIC) {
    webTarget.register(
        HttpAuthenticationFeature.basic(webhookConfig.username, webhookConfig.password)
    );
  }

  if (webhookConfig.authType == AuthenticationType.DIGEST) {
    webTarget.register(
        HttpAuthenticationFeature.digest(webhookConfig.username, webhookConfig.password)
    );
  }

  if (webhookConfig.authType == AuthenticationType.UNIVERSAL) {
    webTarget.register(
        HttpAuthenticationFeature.universal(webhookConfig.username, webhookConfig.password)
    );
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:AlertManager.java

示例8: 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

示例9: 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

示例10: 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

示例11: testGetUsers

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
private void testGetUsers(String usersListURI, HttpAuthenticationFeature loginFeature) throws Exception {
  Response response = ClientBuilder
      .newClient()
      .target(usersListURI)
      .register(loginFeature)
      .request()
      .get();
  Assert.assertEquals(200, response.getStatus());
  List<UserJson> usersList = response.readEntity(new GenericType<List<UserJson>>(){});
  Assert.assertNotNull(usersList);
  Assert.assertEquals(2, usersList.size());

  UserJson adminUser = usersList.get(0);
  Assert.assertEquals("admin", adminUser.getName());
  Assert.assertEquals(1, adminUser.getRoles().size());
  Assert.assertEquals(3, adminUser.getGroups().size());
  Assert.assertEquals("all", adminUser.getGroups().get(0));
  Assert.assertEquals("group1", adminUser.getGroups().get(1));
  Assert.assertEquals("group2", adminUser.getGroups().get(2));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:21,代码来源:TestUserGroupManager.java

示例12: 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

示例13: 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

示例14: initIcingaClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
@PostConstruct
public void initIcingaClient() {
    icingaClient = ClientBuilder.newBuilder()
            //disable hostname verification
            .hostnameVerifier((s, sslSession) -> true)
            //ignore SSLHandshakes
            .sslContext(getTrustEverythingSSLContext())
            .build()
            .register(HttpAuthenticationFeature.basic(properties.getApiUsername(), properties.getApiPassword()))
            .register(new ErrorResponseFilter())
            .register(JacksonFeature.class);

    if (LOGGER.isDebugEnabled()) {
        icingaClient.register(LoggingFilter.class);
    }
}
 
开发者ID:ConSol,项目名称:sakuli,代码行数:17,代码来源:Icinga2RestCient.java

示例15: testInitIcingaClient

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; //导入依赖的package包/类
@Test
public void testInitIcingaClient() throws Exception {
    // testling.initIcingaClient() will be called on context startup
    Set<Object> registeredObjects = ((Client) ReflectionTestUtils.getField(testling, "icingaClient")).getConfiguration().getInstances();
    assertEquals(registeredObjects.size(), 2);
    registeredObjects.forEach(e -> {
        if (e instanceof HttpAuthenticationFeature) {
            assertNotNull(ReflectionTestUtils.getField(e, "basicCredentials"));
            return;
        }
        if (e instanceof Icinga2RestCient.ErrorResponseFilter) {
            return;
        }
        throw new RuntimeException("not epected class of registered Object of 'icingaClient'");
    });
}
 
开发者ID:ConSol,项目名称:sakuli,代码行数:17,代码来源:Icinga2RestCientTest.java


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