当前位置: 首页>>代码示例>>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;未经允许,请勿转载。