use of com.nimbusds.jose.JWSHeader in project carbon-apimgt by wso2.
the class InternalAPIKeyGenerator method generateToken.
public String generateToken(JwtTokenInfoDTO jwtTokenInfoDTO) throws APIManagementException {
JWSHeader jwtHeader = buildHeader();
JWTClaimsSet jwtBody = buildBody(jwtTokenInfoDTO);
SignedJWT signedJWT = new SignedJWT(jwtHeader, jwtBody);
// get the assertion signed
buildSignature(signedJWT);
if (log.isDebugEnabled()) {
log.debug("signed assertion value : " + signedJWT.getParsedString());
}
return signedJWT.serialize();
}
use of com.nimbusds.jose.JWSHeader in project flow by vaadin.
the class JwtSecurityContextRepositoryTest method saveContext_doesNotSaveJwt_when_algorithmHasNoKey.
@Test
public void saveContext_doesNotSaveJwt_when_algorithmHasNoKey() throws JOSEException {
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
JWSHeader header = getHeaderBuilder().build();
JWTClaimsSet claimsSet = getClaimsSetBuilder().build();
Mockito.doReturn(getJwtAuthenticationToken(header, claimsSet)).when(securityContext).getAuthentication();
jwtSecurityContextRepository.setJwsAlgorithm(JWSAlgorithm.HS512);
jwtSecurityContextRepository.saveContext(securityContext, request, response);
String serializedJwt = getSavedSerializedJwt();
Assert.assertNull(serializedJwt);
}
use of com.nimbusds.jose.JWSHeader in project flow by vaadin.
the class JwtSecurityContextRepositoryTest method saveContext_doesNotSaveJwt_when_keySourceReturnsEmpty.
@Test
public void saveContext_doesNotSaveJwt_when_keySourceReturnsEmpty() throws JOSEException {
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
JWSHeader header = getHeaderBuilder().build();
JWTClaimsSet claimsSet = getClaimsSetBuilder().build();
Mockito.doReturn(getJwtAuthenticationToken(header, claimsSet)).when(securityContext).getAuthentication();
jwtSecurityContextRepository.setJwkSource((jwkSelector, context) -> new ArrayList<>());
Assert.assertThrows(IndexOutOfBoundsException.class, () -> jwtSecurityContextRepository.saveContext(securityContext, request, response));
String serializedJwt = getSavedSerializedJwt();
Assert.assertNull(serializedJwt);
}
use of com.nimbusds.jose.JWSHeader in project flow by vaadin.
the class JwtSecurityContextRepositoryTest method saveContext_doesSaveJwt_withAlgoritm.
@Test
public void saveContext_doesSaveJwt_withAlgoritm() throws JOSEException, BadJOSEException, ParseException {
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
JWSHeader header = getHeaderBuilder().build();
JWTClaimsSet claimsSet = getClaimsSetBuilder().build();
Mockito.doReturn(getJwtAuthenticationToken(header, claimsSet)).when(securityContext).getAuthentication();
final ImmutableSecret secret = new ImmutableSecret<>(TEST_64BYTE_KEY.getEncoded());
jwtSecurityContextRepository.setJwkSource(secret);
jwtSecurityContextRepository.setJwsAlgorithm(JWSAlgorithm.HS512);
jwtSecurityContextRepository.saveContext(securityContext, request, response);
jwtProcessor.setJWSKeySelector(new JWSVerificationKeySelector<>(JWSAlgorithm.HS512, secret));
String serializedJwt = getSavedSerializedJwt();
JWTClaimsSet decodedClaimsSet = decodeSerializedJwt(serializedJwt, jwtProcessor);
assertClaims(decodedClaimsSet, TEST_USERNAME, TEST_ROLES, 1800);
}
use of com.nimbusds.jose.JWSHeader in project flow by vaadin.
the class JwtSecurityContextRepositoryTest method saveContext_doesSaveJwt_withOtherKey.
@Test
public void saveContext_doesSaveJwt_withOtherKey() throws JOSEException, BadJOSEException, ParseException {
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
JWSHeader header = getHeaderBuilder().build();
JWTClaimsSet claimsSet = getClaimsSetBuilder().build();
Mockito.doReturn(getJwtAuthenticationToken(header, claimsSet)).when(securityContext).getAuthentication();
final ImmutableSecret secret = new ImmutableSecret<>(TEST_OTHER_KEY);
jwtSecurityContextRepository.setJwkSource(secret);
jwtSecurityContextRepository.saveContext(securityContext, request, response);
jwtProcessor.setJWSKeySelector(new JWSVerificationKeySelector<>(JWSAlgorithm.HS256, secret));
String serializedJwt = getSavedSerializedJwt();
JWTClaimsSet decodedClaimsSet = decodeSerializedJwt(serializedJwt, jwtProcessor);
assertClaims(decodedClaimsSet, TEST_USERNAME, TEST_ROLES, 1800);
}
Aggregations