Search in sources :

Example 71 with SignedJWT

use of com.nimbusds.jwt.SignedJWT in project pac4j by pac4j.

the class SecretSignatureConfigurationTests method testSignVerify.

@Test
public void testSignVerify() throws JOSEException {
    final SecretSignatureConfiguration config = new SecretSignatureConfiguration(MAC_SECRET);
    final JWTClaimsSet claims = new JWTClaimsSet.Builder().subject(VALUE).build();
    final SignedJWT signedJwt = config.sign(claims);
    assertTrue(config.verify(signedJwt));
}
Also used : JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) SignedJWT(com.nimbusds.jwt.SignedJWT) Test(org.junit.Test)

Example 72 with SignedJWT

use of com.nimbusds.jwt.SignedJWT in project connect-android-sdk by telenordigital.

the class IdTokenValidatorTest method authorizedPartyNotEqualClientThrows.

@Test(expected = ConnectException.class)
public void authorizedPartyNotEqualClientThrows() 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);
    claimsSet.setIssueTime(now);
    claimsSet.setCustomClaim("azp", "NOT connect-tests");
    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);
}
Also used : IdToken(com.telenor.connect.id.IdToken) ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) BigInteger(java.math.BigInteger) SignedJWT(com.nimbusds.jwt.SignedJWT) JWSHeader(com.nimbusds.jose.JWSHeader) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with SignedJWT

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);
}
Also used : IdToken(com.telenor.connect.id.IdToken) ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) BigInteger(java.math.BigInteger) SignedJWT(com.nimbusds.jwt.SignedJWT) JWSHeader(com.nimbusds.jose.JWSHeader) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with SignedJWT

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());
}
Also used : IdToken(com.telenor.connect.id.IdToken) ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Calendar(java.util.Calendar) BigInteger(java.math.BigInteger) SignedJWT(com.nimbusds.jwt.SignedJWT) JWSHeader(com.nimbusds.jose.JWSHeader) BeforeClass(org.junit.BeforeClass)

Example 75 with SignedJWT

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();
}
Also used : RSASSASigner(com.nimbusds.jose.crypto.RSASSASigner) SignedJWT(com.nimbusds.jwt.SignedJWT) JWSSigner(com.nimbusds.jose.JWSSigner) JWSHeader(com.nimbusds.jose.JWSHeader)

Aggregations

SignedJWT (com.nimbusds.jwt.SignedJWT)204 Test (org.junit.Test)84 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)75 Date (java.util.Date)66 HttpServletRequest (javax.servlet.http.HttpServletRequest)64 HttpServletResponse (javax.servlet.http.HttpServletResponse)54 JWSHeader (com.nimbusds.jose.JWSHeader)53 Properties (java.util.Properties)49 ServletException (javax.servlet.ServletException)46 ParseException (java.text.ParseException)31 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)28 JOSEException (com.nimbusds.jose.JOSEException)25 JWSSigner (com.nimbusds.jose.JWSSigner)21 Cookie (javax.servlet.http.Cookie)21 ArrayList (java.util.ArrayList)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 SignedJWTInfo (org.wso2.carbon.apimgt.impl.jwt.SignedJWTInfo)13 Test (org.junit.jupiter.api.Test)12 OAuth2TokenValidator (org.springframework.security.oauth2.core.OAuth2TokenValidator)12 Cache (javax.cache.Cache)11