RoleToken extends Token { private RoleToken(Builder builder) { this.version = builder.version; this.domain = builder.domain; this.roles = builder.roles; this.host = builder.host; this.salt = builder.salt; this.keyId = builder.keyId; this.ip = builder.ip; this.principal = builder.principal; this.proxyUser = builder.proxyUser; this.domainCompleteRoleSet = builder.domainCompleteRoleSet; super.setTimeStamp(builder.issueTime, builder.expirationWindow); StringBuilder strBuilder = new StringBuilder(defaultBuilderBufSize); strBuilder.append("v="); strBuilder.append(version); strBuilder.append(";d="); strBuilder.append(domain); strBuilder.append(";r="); int i = 0; for (String role : roles) { strBuilder.append(role); if (++i != roles.size()) { strBuilder.append(","); } } if (domainCompleteRoleSet) { strBuilder.append(";c=1"); } if (principal != null && !principal.isEmpty()) { strBuilder.append(";p="); strBuilder.append(principal); } if (host != null && !host.isEmpty()) { strBuilder.append(";h="); strBuilder.append(host); } if (proxyUser != null && !proxyUser.isEmpty()) { strBuilder.append(";proxy="); strBuilder.append(proxyUser); } strBuilder.append(";a="); strBuilder.append(salt); strBuilder.append(";t="); strBuilder.append(timestamp); strBuilder.append(";e="); strBuilder.append(expiryTime); strBuilder.append(";k="); strBuilder.append(keyId); if (ip != null && !ip.isEmpty()) { strBuilder.append(";i="); strBuilder.append(ip); } unsignedToken = strBuilder.toString(); if (LOG.isDebugEnabled()) { LOG.debug("RoleToken created: " + unsignedToken); } } private  RoleToken(Builder builder);  RoleToken(String signedToken); String getPrincipal(); List<String> getRoles(); String getProxyUser(); boolean getDomainCompleteRoleSet();  }
@Test public void testRoleToken() throws CryptoException { List<String> roles = new ArrayList<>(); roles.add("storage.tenant.weather.updater"); roles.add("fantasy.tenant.sports.admin"); roles.add("fantasy.tenant.sports.reader"); roles.add("fantasy.tenant.sports.writer"); roles.add("fantasy.tenant.sports.scanner"); String testKeyVersionK1 = "1"; RoleToken rollTokenToValidate = createRoleTokenToValidate(roles, testKeyVersionK1); assertNotNull(rollTokenToValidate.getSignedToken()); assertEquals(rollTokenToValidate.getVersion(), rolVersion); assertEquals(rollTokenToValidate.getDomain(), svcDomain); List<String> rolesToValidate = rollTokenToValidate.getRoles(); assertEquals(rolesToValidate.size(), roles.size()); assertEquals(rolesToValidate, roles); assertEquals(rollTokenToValidate.getKeyId(), testKeyVersionK1); assertTrue(rollTokenToValidate.validate(ztsPublicKeyStringK1, 300, false)); rollTokenToValidate = createRoleTokenToValidate(roles); assertEquals(rollTokenToValidate.getKeyId(), "0"); assertTrue(rollTokenToValidate.validate(ztsPublicKeyStringK0, 300, false)); }