Token { public String getUnsignedToken() { return unsignedToken; }  String getDigestAlgorithm(); void sign(String privKey); void sign(PrivateKey key); void setTimeStamp(long issueTime, long expirationWindow); boolean validate(String pubKey, int allowedOffset); boolean validate(String pubKey, int allowedOffset, boolean allowNoExpiry); boolean validate(String pubKey, int allowedOffset, boolean allowNoExpiry,
            StringBuilder errMsg); boolean validate(PublicKey publicKey, int allowedOffset, boolean allowNoExpiry,
            StringBuilder errMsg); String getVersion(); String getSalt(); String getHost(); String getDomain(); String getSignature(); long getTimestamp(); long getExpiryTime(); String getSignedToken(); String getKeyId(); String getIP(); String getUnsignedToken(); static String getUnsignedToken(String credential);  }
@Test public void testGetUnsignedTokenFromSignedToken() { String [] signedTokens = { "v=Z1;d=sports;r=storage.tenant.weather.updater;p=user.joe;a=aAkjbbDMhnLX;t=1447361682;e=1447361692;k=0;i=127.0.0.1;s=IKT3MhlfxMajh9KqvNFhuJwyHQB8M9qVmgok389wmcRZ_kqMKaf72sC3.u0Qh4VlWk.DReX8y17V.qV0wnGwNPwfUBKG9SR88SL_MBvSaVHst9wQN20v.gCzFf8IXzehEFID5tjCIFAmaLEn71bCS4oKMiPEx4FtP4OdYdeL_d4", "v=Z1;d=sports;r=storage.tenant.weather.updater,fantasy.tenant.sports.admin,fantasy.tenant.sports.reader,fantasy.tenant.sports.writer,fantasy.tenant.sports.scanner;p=coretech.storage;a=aAkjbbDMhnLX;t=1447361682;e=1447361692;k=0;i=127.0.0.1;s=C68KMYxivWqTTg8YWGc1aXUkgbgHOQDH8iRePZWY9aLUidkEQSvBkveRFi4Sap6q800Qt1GVnF6aN1OMk6YNIc_0E_xdRj9LJriS6Qq6ss79y76J_OSGSIwBXNeDWP6fq1SPW_MlUiXPE3TJojG_W8C0lwtWRppP0UZGAjzs4bc-", "v=S1;d=cd.project;n=nfl;h=somehost.somecompany.com;a=saltvalue;t=1447361732;e=1447361742;s=NlISFQqXz1ji8zdVdGKjKZHJBloo11S.tXLo6t.GmnCt9S6c8AATzzZ2XdMeRlX2b0ykRiS0yjmrXg.grMPin3cHiB_FdLL05.w29OUBgxJr71.11_09iOoqy0ivGqyXoSO2GQbtXJfQeJ6HFHWPef1xyNV0Fswd8e6HQtyxGLA-", "v=S1;d=cd;n=12345;h=somehost.somecompany.com;a=saltvalue;t=1447361732;e=1447361742;k=0;s=lg5JMqJb9Hd5Vd12VdC2d.Pu0TSlynGtulV7GjT9RQsSFaTsvabLPIehNT7iJczVq_POzWTA7HYRe7ZNGfGTe6P26C_qECX._ylbYVznLnZSFW3IQFMMPc2yjiE_twFgXAVtT1sWHjcf8zxK4RVij_8vziTiUrqU_ExioO019XE-", }; for (String signedToken: signedTokens) { String unsignedToken = Token.getUnsignedToken(signedToken); assertNotEquals(unsignedToken, signedToken); assertTrue(unsignedToken.length() < signedToken.length()); assertTrue(signedToken.startsWith(unsignedToken)); } }
@Test public void testGetUnsignedTokenFromUnsignedToken() { String [] signedTokens = { "v=Z1;d=sports;r=storage.tenant.weather.updater;p=user.joe;a=aAkjbbDMhnLX;t=1447361682;e=1447361692;k=0;i=127.0.0.1", "v=Z1;d=sports;r=storage.tenant.weather.updater,fantasy.tenant.sports.admin,fantasy.tenant.sports.reader,fantasy.tenant.sports.writer,fantasy.tenant.sports.scanner;p=coretech.storage;a=aAkjbbDMhnLX;t=1447361682;e=1447361692;k=0;i=127.0.0.1", "v=S1;d=cd.project;n=nfl;h=somehost.somecompany.com;a=saltvalue;t=1447361732;e=1447361742", "v=S1;d=cd;n=12345;h=somehost.somecompany.com;a=saltvalue;t=1447361732;e=1447361742;k=0", }; for (String signedToken: signedTokens) { String unsignedToken = Token.getUnsignedToken(signedToken); assertSame(unsignedToken, signedToken); } }