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


Java JsonWebKey.setKeyId方法代码示例

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


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

示例1: extractX509Certificate

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
private JsonWebKeySet extractX509Certificate(String json) {
  Map<String, String> certificates = parse(json, new TypeReference<Map<String, String>>() {});
  ImmutableList.Builder<JsonWebKey> jwkBuilder = ImmutableList.builder();
  X509Util x509Util = new X509Util();
  for (Entry<String, String> entry : certificates.entrySet()) {
    try {
      String cert = entry.getValue().trim()
          .replace(X509_CERT_PREFIX, "")
          .replace(X509_CERT_SUFFIX, "");
      X509Certificate x509Certificate = x509Util.fromBase64Der(cert);
      PublicKey publicKey = x509Certificate.getPublicKey();
      JsonWebKey jwk = toJsonWebKey(publicKey);
      jwk.setKeyId(entry.getKey());
      jwkBuilder.add(jwk);
    } catch (JoseException exception) {
      throw new UnauthenticatedException("Failed to parse public key", exception);
    }
  }
  return new JsonWebKeySet(jwkBuilder.build());
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefaultJwksSupplier.java

示例2: testSuccessClientGeneratedECKeys

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testSuccessClientGeneratedECKeys() throws Exception {

	JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
	popKey.setKeyId("testkid");
	
	TokenRequest req = new TokenRequest();
	req.setGrantType("client_credentials");
	req.setAud(config.getResourceServers().get(0).getAud());
	req.setClientID(config.getClients().get(0).getClient_id());
	req.setClientSecret(config.getClients().get(0).getClient_secret());
	req.setScopes(config.getResourceServers().get(0).getScopes());
	req.setKey(popKey);

	Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());		

	Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
	
	TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);

	TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
 
开发者ID:erwah,项目名称:acetest,代码行数:23,代码来源:TokenResourceTest.java

示例3: testSuccessClientGeneratedRSAKeys

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testSuccessClientGeneratedRSAKeys() throws Exception {

	JsonWebKey popKey = RsaJwkGenerator.generateJwk(2048);
	popKey.setKeyId("testkid");
	
	TokenRequest req = new TokenRequest();
	req.setGrantType("client_credentials");
	req.setAud(config.getResourceServers().get(0).getAud());
	req.setClientID(config.getClients().get(0).getClient_id());
	req.setClientSecret(config.getClients().get(0).getClient_secret());
	req.setScopes(config.getResourceServers().get(0).getScopes());
	req.setKey(popKey);

	Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());		

	Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
	
	TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);

	TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
 
开发者ID:erwah,项目名称:acetest,代码行数:23,代码来源:TokenResourceTest.java

示例4: testScopes

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testScopes() throws Exception {

	JsonWebKey jwk;
	jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
	jwk.setKeyId("testkid");
	
	TokenRequest req = new TokenRequest();
	req.setGrantType("client_credentials");
	req.setAud(config.getResourceServers().get(0).getAud());
	req.setClientID(config.getClients().get(0).getClient_id());
	req.setClientSecret(config.getClients().get(0).getClient_secret());
	req.setScopes(config.getResourceServers().get(0).getScopes());
	req.setKey(jwk);

	Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());		

	TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);

	TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
 
开发者ID:erwah,项目名称:acetest,代码行数:22,代码来源:TokenResourceTest.java

示例5: testSuccess

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testSuccess() throws Exception {
	// first create a token
	JsonWebKey jwk;
	jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
	jwk.setKeyId("testkid");
	
	TokenRequest createReq = new TokenRequest();
	createReq.setGrantType("client_credentials");
	createReq.setAud(config.getResourceServers().get(0).getAud());
	createReq.setClientID(config.getClients().get(0).getClient_id());
	createReq.setClientSecret(config.getClients().get(0).getClient_secret());
	createReq.setScopes(config.getResourceServers().get(0).getScopes());
	createReq.setKey(jwk);


	Response createResponse = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", createReq.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());		
	Assert.assertEquals(ResponseCode.CONTENT, createResponse.getCode());
	
	TokenResponse tokenResponse = new TokenResponse(createResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
	
	// see of token is valid 
	IntrospectRequest introspectionReq = new IntrospectRequest();
	introspectionReq.setToken(tokenResponse.getAccessToken());
	introspectionReq.setClientID(config.getClients().get(0).getClient_id());
	introspectionReq.setClientSecret(config.getClients().get(0).getClient_secret());
	
	Response introspectionResponse = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.INSTROSPECTION_RESOURCE, "POST", introspectionReq.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());	

	Assert.assertEquals(introspectionResponse.getCode(), ResponseCode.CONTENT);

	IntrospectResponse introspectResponse = new IntrospectResponse(introspectionResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
	Assert.assertTrue(introspectResponse.isActive());
}
 
开发者ID:erwah,项目名称:acetest,代码行数:35,代码来源:IntrospectResourceTest.java

示例6: testSuccessPlaintext

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
@Test
public void testSuccessPlaintext() throws Exception {

	// first create a token
	JsonWebKey jwk;
	jwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);
	jwk.setKeyId("testkid");
	
	TokenRequest createReq = new TokenRequest();
	createReq.setGrantType("client_credentials");
	createReq.setAud(config.getResourceServers().get(0).getAud());
	createReq.setClientID(config.getClients().get(0).getClient_id());
	createReq.setClientSecret(config.getClients().get(0).getClient_secret());
	createReq.setScopes(config.getResourceServers().get(0).getScopes());
	createReq.setKey(jwk);
	
	Request request = Request.newPost();
	request.setURI("coap://localhost:"+config.getCoapPort()+"/"+Constants.TOKEN_RESOURCE);
	request.setPayload(createReq.toPayload(MediaTypeRegistry.APPLICATION_JSON));
	request.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON);

	Response createResponse = request.send().waitForResponse();

	Assert.assertEquals(ResponseCode.CONTENT, createResponse.getCode());
	
	TokenResponse tokenResponse = new TokenResponse(createResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
	
	// see of token is valid 
	IntrospectRequest introspectionReq = new IntrospectRequest();
	introspectionReq.setToken(tokenResponse.getAccessToken());
	introspectionReq.setClientID(config.getClients().get(0).getClient_id());
	introspectionReq.setClientSecret(config.getClients().get(0).getClient_secret());
	
	Request introspectionRequest = Request.newPost();
	introspectionRequest.setURI("coap://localhost:"+config.getCoapPort()+"/"+Constants.INSTROSPECTION_RESOURCE);
	introspectionRequest.setPayload(introspectionReq.toPayload(MediaTypeRegistry.APPLICATION_JSON));
	introspectionRequest.getOptions().setContentFormat(MediaTypeRegistry.APPLICATION_JSON);

	Response introspectionResponse = introspectionRequest.send().waitForResponse();

	Assert.assertEquals(introspectionResponse.getCode(), ResponseCode.CONTENT);
	
	IntrospectResponse introspectResponse = new IntrospectResponse(introspectionResponse.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
	Assert.assertTrue(introspectResponse.isActive());
}
 
开发者ID:erwah,项目名称:acetest,代码行数:46,代码来源:IntrospectResourceTest.java

示例7: asymmetricEcClient

import org.jose4j.jwk.JsonWebKey; //导入方法依赖的package包/类
private static void asymmetricEcClient() throws JoseException {
	
	JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
	// generate a unique kid for the newly generated key
    String kid = new BigInteger(130, random).toString(32);
	popKey.setKeyId(kid);
	
	TokenRequest req = new TokenRequest();
	req.setGrantType("client_credentials");
	req.setAud(config.getRsAud());
	req.setClientID(config.getClientId());
	req.setClientSecret(config.getClientSecret());
	req.setScopes(config.getRsScopes());
	// add key to the request so that public part can be sent to AS
	req.setKey(popKey);
	
	Response response;
	try {
		// send token request to AS and include the public key
		response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getAsCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getAsPskIdentity(), config.getAsPskKey().getBytes());
		TokenResponse tokenResponse = new TokenResponse(response.getPayload(), response.getOptions().getContentFormat());
		String accessToken = tokenResponse.getAccessToken();
		EllipticCurveJsonWebKey rpk = tokenResponse.getRpk();

		if(rpk != null) {
			String keyType = rpk.getKeyType();
			
			PublicKey publicKey = null;
			
			if(keyType.equalsIgnoreCase("ec")) {
				EllipticCurveJsonWebKey ecjwk = new EllipticCurveJsonWebKey((ECPublicKey) rpk.getKey());
				publicKey = ecjwk.getPublicKey();
			}
			else if(keyType.equalsIgnoreCase("rsa")) {
				RsaJsonWebKey rsajwk = new RsaJsonWebKey((RSAPublicKey) rpk.getKey());
				publicKey = rsajwk.getPublicKey();
			}

			ArrayList<PublicKey> trustedPublicKeys = new ArrayList<PublicKey>();
			trustedPublicKeys.add(publicKey);
			
			// send key to resource servers authz-info resource over unencrypted DTLS
			Request authzInfoRequest = Request.newPost();
			authzInfoRequest.setURI("coap://localhost:"+config.getRsCoapPort()+"/"+Constants.AUTHZ_INFO_RESOURCE);
			authzInfoRequest.getOptions().setContentFormat(Constants.MediaTypeRegistry_APPLICATION_JWT);
			authzInfoRequest.setPayload(accessToken.getBytes());
			Response authzInfoResponse = authzInfoRequest.send().waitForResponse();
			
			if(authzInfoResponse.getCode() == ResponseCode.CREATED) {
				// get the temperature
				response = DTLSUtils.dtlsRPKRequest("coaps://localhost:"+config.getRsCoapsPort()+"/temperature", "POST", "".getBytes(), MediaTypeRegistry.APPLICATION_JSON, popKey, trustedPublicKeys);
				TemperatureResponse temperatureResponse = new TemperatureResponse(response.getPayload(), response.getOptions().getContentFormat());
				logger.info("Temp: " + temperatureResponse);
			}
			else {
				logger.info("Access token not valid. Response code: " + response.getCode());
			}
		}

	} catch (Exception e) {
		logger.error(e);
	}
}
 
开发者ID:erwah,项目名称:acetest,代码行数:64,代码来源:ClientRPK.java


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