Search in sources :

Example 1 with ECDSASigner

use of com.nimbusds.jose.crypto.ECDSASigner 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 2 with ECDSASigner

use of com.nimbusds.jose.crypto.ECDSASigner 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 3 with ECDSASigner

use of com.nimbusds.jose.crypto.ECDSASigner 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 4 with ECDSASigner

use of com.nimbusds.jose.crypto.ECDSASigner in project pac4j by pac4j.

the class ECSignatureConfiguration method sign.

@Override
public SignedJWT sign(JWTClaimsSet claims) {
    init();
    CommonHelper.assertNotNull("privateKey", privateKey);
    try {
        final JWSSigner signer = new ECDSASigner(this.privateKey);
        final SignedJWT signedJWT = new SignedJWT(new JWSHeader(algorithm), claims);
        signedJWT.sign(signer);
        return signedJWT;
    } catch (final JOSEException e) {
        throw new TechnicalException(e);
    }
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) SignedJWT(com.nimbusds.jwt.SignedJWT)

Example 5 with ECDSASigner

use of com.nimbusds.jose.crypto.ECDSASigner in project connect-android-sdk by telenordigital.

the class IdTokenValidatorTest method expiredTimeThrows.

@Test(expected = ConnectException.class)
public void expiredTimeThrows() 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(twoHoursAgo);
    claimsSet.setIssueTime(now);
    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)

Aggregations

ECDSASigner (com.nimbusds.jose.crypto.ECDSASigner)5 SignedJWT (com.nimbusds.jwt.SignedJWT)5 JWSHeader (com.nimbusds.jose.JWSHeader)4 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 IdToken (com.telenor.connect.id.IdToken)4 BigInteger (java.math.BigInteger)4 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Calendar (java.util.Calendar)1 BeforeClass (org.junit.BeforeClass)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1