當前位置: 首頁>>代碼示例>>Java>>正文


Java CreateKeysAndCertificateResult類代碼示例

本文整理匯總了Java中com.amazonaws.services.iot.model.CreateKeysAndCertificateResult的典型用法代碼示例。如果您正苦於以下問題:Java CreateKeysAndCertificateResult類的具體用法?Java CreateKeysAndCertificateResult怎麽用?Java CreateKeysAndCertificateResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CreateKeysAndCertificateResult類屬於com.amazonaws.services.iot.model包,在下文中一共展示了CreateKeysAndCertificateResult類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCertificate

import com.amazonaws.services.iot.model.CreateKeysAndCertificateResult; //導入依賴的package包/類
public Node createCertificate(Node parent, String name) {
    Date creationDate = new Date();
    boolean isActive = true;

    CreateKeysAndCertificateRequest req = new CreateKeysAndCertificateRequest();
    req.setSetAsActive(isActive);

    CreateKeysAndCertificateResult res = client.createKeysAndCertificate(req);

    return new CertificateNode(parent, name, res.getCertificateId(), res.getCertificateArn(),
            res.getCertificatePem(), res.getKeyPair(), creationDate, isActive ? "ACTIVE" : "INACTIVE");
}
 
開發者ID:awslabs,項目名稱:aws-iot-fuse,代碼行數:13,代碼來源:AwsIot.java

示例2: createThing

import com.amazonaws.services.iot.model.CreateKeysAndCertificateResult; //導入依賴的package包/類
@Override
public Thing createThing(Thing thing) {
	if (thing == null || StringUtils.isBlank(thing.getName()) || StringUtils.isBlank(thing.getAppid()) ||
			existsThing(thing)) {
		return null;
	}
	thing.setId(Utils.getNewId());
	String id = cloudIDForThing(thing);
	String appid = thing.getAppid();

	// STEP 1: Create thing
	CreateThingResult resp1 = getClient().createThing(new CreateThingRequest().withThingName(id).
			withAttributePayload(new AttributePayload().addAttributesEntry(Config._APPID, appid)));

	// STEP 2: Create certificate
	CreateKeysAndCertificateResult resp2 = getClient().createKeysAndCertificate(
			new CreateKeysAndCertificateRequest().withSetAsActive(true));

	String accountId = getAccountIdFromARN(resp1.getThingArn());
	String policyString = (String) (thing.getDeviceMetadata().containsKey("policyJSON") ?
			thing.getDeviceMetadata().get("policyJSON") : getDefaultPolicyDocument(accountId, id));

	// STEP 3: Create policy
	getClient().createPolicy(new CreatePolicyRequest().
			withPolicyDocument(policyString).withPolicyName(id + "-Policy"));

	// STEP 4: Attach policy to certificate
	getClient().attachPrincipalPolicy(new AttachPrincipalPolicyRequest().
			withPrincipal(resp2.getCertificateArn()).withPolicyName(id + "-Policy"));

	// STEP 5: Attach thing to certificate
	getClient().attachThingPrincipal(new AttachThingPrincipalRequest().
			withPrincipal(resp2.getCertificateArn()).withThingName(id));

	thing.getDeviceMetadata().remove("policyJSON");

	thing.setServiceBroker("AWS");
	thing.getDeviceMetadata().put("thingId", thing.getId());
	thing.getDeviceMetadata().put("thingName", id);
	thing.getDeviceMetadata().put("thingARN", resp1.getThingArn());
	thing.getDeviceMetadata().put("clientId", id);
	thing.getDeviceMetadata().put("clientCertId", resp2.getCertificateId());
	thing.getDeviceMetadata().put("clientCertARN", resp2.getCertificateArn());
	thing.getDeviceMetadata().put("clientCert", resp2.getCertificatePem());
	thing.getDeviceMetadata().put("privateKey", resp2.getKeyPair().getPrivateKey());
	thing.getDeviceMetadata().put("publicKey", resp2.getKeyPair().getPublicKey());
	thing.getDeviceMetadata().put("region", Config.AWS_REGION);
	thing.getDeviceMetadata().put("port", 8883);
	thing.getDeviceMetadata().put("host", getClient().
			describeEndpoint(new DescribeEndpointRequest()).getEndpointAddress());

	return thing;
}
 
開發者ID:Erudika,項目名稱:para,代碼行數:54,代碼來源:AWSIoTService.java


注:本文中的com.amazonaws.services.iot.model.CreateKeysAndCertificateResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。