use of com.zimbra.cs.account.AuthTokenProperties in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testGetJWToken.
@Test
public void testGetJWToken() {
Account acct;
try {
acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
String salt = "s1";
String salts = "s2|s3|s1";
AuthTokenKey atkey = AuthTokenUtil.getCurrentKey();
byte[] jwtKey = Bytes.concat(atkey.getKey(), salt.getBytes());
long issuedAt = System.currentTimeMillis();
long expires = issuedAt + 3600000;
AuthTokenProperties properties = new AuthTokenProperties(acct, true, null, expires, AuthMech.zimbra, Usage.AUTH);
String jwt = JWTUtil.generateJWT(jwtKey, salt, issuedAt, properties, atkey.getVersion());
AuthToken at = ZimbraJWToken.getJWToken(jwt, salts);
Assert.assertEquals(acct.getId(), at.getAccountId());
Assert.assertEquals(Usage.AUTH, at.getUsage());
Assert.assertEquals(expires / 1000, at.getExpires() / 1000);
Assert.assertEquals(AuthMech.zimbra, at.getAuthMech());
Assert.assertEquals(false, at.isAdmin());
} catch (ServiceException | AuthTokenException e) {
e.printStackTrace();
Assert.fail("testGenerateAndValidateJWT failed");
}
}
use of com.zimbra.cs.account.AuthTokenProperties in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method generateJWT.
private String generateJWT(Account acct, String salt) throws AuthFailedServiceException, AuthTokenException {
AuthTokenKey atkey = AuthTokenUtil.getCurrentKey();
byte[] jwtKey = Bytes.concat(atkey.getKey(), salt.getBytes());
long issuedAt = System.currentTimeMillis();
long expires = issuedAt + 3600000;
AuthTokenProperties properties = new AuthTokenProperties(acct, false, null, expires, null, Usage.AUTH);
String jwt = JWTUtil.generateJWT(jwtKey, salt, issuedAt, properties, atkey.getVersion());
return jwt;
}
Aggregations