use of com.nimbusds.jose.jwk.source.ImmutableSecret in project flow by vaadin.
the class JwtSecurityContextRepositoryTest method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.openMocks(this);
SecurityContextHolder.setStrategyName(TestSecurityContextHolderStrategy.class.getName());
final ImmutableSecret secret = new ImmutableSecret<>(TEST_KEY);
holder = new HttpRequestResponseHolder(request, response);
jwtSecurityContextRepository = new JwtSecurityContextRepository(serializedJwtSplitCookieRepository);
jwtSecurityContextRepository.setJwkSource(secret);
jwtSecurityContextRepository.setJwsAlgorithm(JWSAlgorithm.HS256);
// Processor for asserting saved JWTs
jwtProcessor = new DefaultJWTProcessor<>();
jwtProcessor.setJWSKeySelector(new JWSVerificationKeySelector<>(JWSAlgorithm.HS256, secret));
}
use of com.nimbusds.jose.jwk.source.ImmutableSecret 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.jwk.source.ImmutableSecret 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