Skip to content

Instantly share code, notes, and snippets.

@henryean
Created April 24, 2020 08:04
Show Gist options
  • Save henryean/df736f2e044c6222c3784edd02c1b91d to your computer and use it in GitHub Desktop.
Save henryean/df736f2e044c6222c3784edd02c1b91d to your computer and use it in GitHub Desktop.
SWID Tag Generator Example
DefaultSwidProcessor processor = new DefaultSwidProcessor();
processor.setGenerator(new SequentialIdGenerator(0, 1, "e", null));
processor.setName("NetLicensing")
.setVersion("2.1.0")
.setVersionScheme(VersionScheme.UNKNOWN)
.setSupplemental(true)
.addEntity(new EntityBuilder().name("Labs64")
.role("softwareCreator")
.role("softwareLicensor")
.role("tagCreator")
.build())
.addLink(new LinkBuilder().rel("supplemental")
.href("swid:other-swid-tag")
.build())
.addMetaData(new SoftwareMetaBuilder().description("This is what it's about")
.entitlementDataRequired(true)
.revision("3")
.build())
.addEvidence(new EvidenceBuilder()
.deviceId("123-a")
.date(new Date())
.directoryOrFileOrProcess(new FileBuilder()
.name("File.xml")
.size(BigInteger.TEN)
.version("3")
.build())
.build())
.addPayload(new PayloadBuilder()
.directory(new DirectoryBuilder()
.root("/data")
.key(true)
.location("/folder")
.build())
.build());
// create builder and pass processor as build param
SwidBuilder builder = new SwidBuilder();
SoftwareIdentity swidTag = builder.build(processor);
// output resulting object
SwidWriter writer = new SwidWriter();
StringWriter out = new StringWriter();
writer.write(swidTag, out);
System.out.println(out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment