本文整理汇总了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");
}
示例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;
}