use of com.nimbusds.jwt.SignedJWT in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method missingIssueTimeThrows.
@Test(expected = ConnectException.class)
public void missingIssueTimeThrows() throws Exception {
BDDMockito.given(ConnectSdk.getConnectApiUrl()).willReturn(HttpUrl.parse("https://connect.telenordigital.com"));
BDDMockito.given(ConnectSdk.getClientId()).willReturn("connect-tests");
BDDMockito.given(ConnectSdk.getExpectedIssuer()).willReturn("https://connect.telenordigital.com/oauth");
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(oneHourIntoFuture);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
IdToken idToken = new IdToken(signedJWT.serialize());
IdTokenValidator.validate(idToken, null);
}
use of com.nimbusds.jwt.SignedJWT in project connect-android-sdk by telenordigital.
the class IdTokenValidatorTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
Calendar calendar = Calendar.getInstance();
now = calendar.getTime();
calendar.add(Calendar.HOUR, 1);
oneHourIntoFuture = calendar.getTime();
calendar.setTime(now);
calendar.add(Calendar.YEAR, 10);
tenYearsIntoFuture = calendar.getTime();
calendar.setTime(now);
calendar.add(Calendar.HOUR, -2);
twoHoursAgo = calendar.getTime();
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setIssuer("https://connect.telenordigital.com/oauth");
claimsSet.setAudience("connect-tests");
claimsSet.setExpirationTime(oneHourIntoFuture);
claimsSet.setIssueTime(now);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), claimsSet);
signedJWT.sign(new ECDSASigner(new BigInteger("123")));
normalSerializedSignedJwt = new IdToken(signedJWT.serialize());
}
use of com.nimbusds.jwt.SignedJWT in project ovirt-engine by oVirt.
the class OpenIdUtils method createJWT.
/**
* Create a Java web token and sign with the RSA key. Used by the openid userinfo endpoint to send userinfo back.
*/
public static String createJWT(HttpServletRequest request, SsoSession ssoSession, String clientId) throws JOSEException {
// Create RSA-signer with the private key
JWSSigner signer = new RSASSASigner(keyPair.getPrivate());
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), createJWTClaimSet(request, ssoSession, clientId));
signedJWT.sign(signer);
return signedJWT.serialize();
}
use of com.nimbusds.jwt.SignedJWT in project fitpay-android-sdk by fitpay.
the class StringUtils method getDecryptedString.
/**
* Get decrypted string
*
* @param type key type
* @param encryptedString encrypted string
* @return decrypted string
*/
public static String getDecryptedString(@KeysManager.KeyType int type, String encryptedString) {
KeysManager keysManager = KeysManager.getInstance();
JWEObject jweObject;
try {
jweObject = JWEObject.parse(encryptedString);
JWEHeader jweHeader = jweObject.getHeader();
if (jweHeader.getKeyID() == null || jweHeader.getKeyID().equals(keysManager.getKeyId(type))) {
jweObject.decrypt(new AESDecrypter(keysManager.getSecretKey(type)));
if ("JWT".equals(jweObject.getHeader().getContentType())) {
SignedJWT signedJwt = jweObject.getPayload().toSignedJWT();
ECCKeyPair keyPair = keysManager.getPairForType(type);
ECPublicKey key = null;
if ("https://fit-pay.com".equals(signedJwt.getJWTClaimsSet().getIssuer())) {
key = (ECPublicKey) keysManager.getPublicKey("EC", Hex.hexStringToBytes(keyPair.getServerPublicKey()));
} else {
key = (ECPublicKey) keysManager.getPublicKey("EC", Hex.hexStringToBytes(keyPair.getPublicKey()));
}
JWSVerifier verifier = new ECDSAVerifier(key);
if (!signedJwt.verify(verifier)) {
throw new IllegalArgumentException("jwt did not pass signature validation");
}
return signedJwt.getJWTClaimsSet().getStringClaim("data");
} else {
return jweObject.getPayload().toString();
}
}
} catch (Exception e) {
FPLog.e(e);
}
return null;
}
use of com.nimbusds.jwt.SignedJWT in project registry by hortonworks.
the class TestJWTAuthenticationHandler method testExpiredJWT.
@Test
public void testExpiredJWT() throws Exception {
try {
handler.setPublicKey(publicKey);
Properties props = getProperties();
handler.init(props);
SignedJWT jwt = getJWT("bob", new Date(new Date().getTime() - 1000), privateKey);
Cookie cookie = new Cookie("hadoop-jwt", jwt.serialize());
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getCookies()).thenReturn(new Cookie[] { cookie });
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(SERVICE_URL));
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.when(response.encodeRedirectURL(SERVICE_URL)).thenReturn(SERVICE_URL);
AuthenticationToken token = handler.alternateAuthenticate(request, response);
Mockito.verify(response).sendRedirect(REDIRECT_LOCATION);
} catch (ServletException se) {
fail("alternateAuthentication should NOT have thrown a ServletException");
} catch (AuthenticationException ae) {
fail("alternateAuthentication should NOT have thrown a AuthenticationException");
}
}
Aggregations