@Test public void shouldVerifyAuthIdAndFail() throws SignatureException, SSOException, SMSException { SignedJwt signedJwt = mock(SignedJwt.class); PrivateKey privateKey = mock(PrivateKey.class); given(jwtBuilderFactory.reconstruct("AUTH_ID", SignedJwt.class)).willReturn(signedJwt); given(signedJwt.verify(privateKey)).willReturn(false); given(amKeyProvider.getPrivateKey("KEY_ALIAS")).willReturn(privateKey); mockGetKeyAliasMethod("REALM_DN", false); boolean exceptionCaught = false; try { authIdHelper.verifyAuthId("REALM_DN", "AUTH_ID"); fail(); } catch (RestAuthException e) { exceptionCaught = true; } verify(jwtBuilderFactory).reconstruct("AUTH_ID", SignedJwt.class); verify(signedJwt).verify(privateKey); assertTrue(exceptionCaught); }
public void verifyAuthId(String realmDN, String authId) { String keyAlias = getKeyAlias(realmDN); PrivateKey privateKey = amKeyProvider.getPrivateKey(keyAlias); try { boolean verified = jwtBuilderFactory.reconstruct(authId, SignedJwt.class).verify(privateKey); if (!verified) { throw new RestAuthException(Response.Status.BAD_REQUEST, "AuthId JWT Signature not valid"); } } catch (JwtRuntimeException e) { throw new RestAuthException(Response.Status.BAD_REQUEST, "Failed to parse JWT, " + e.getLocalizedMessage(), e); } }
AuthIdHelper { public void verifyAuthId(String realmDN, String authId) { String keyAlias = getKeyAlias(realmDN); PrivateKey privateKey = amKeyProvider.getPrivateKey(keyAlias); try { boolean verified = jwtBuilderFactory.reconstruct(authId, SignedJwt.class).verify(privateKey); if (!verified) { throw new RestAuthException(Response.Status.BAD_REQUEST, "AuthId JWT Signature not valid"); } } catch (JwtRuntimeException e) { throw new RestAuthException(Response.Status.BAD_REQUEST, "Failed to parse JWT, " + e.getLocalizedMessage(), e); } } }
AuthIdHelper { public void verifyAuthId(String realmDN, String authId) { String keyAlias = getKeyAlias(realmDN); PrivateKey privateKey = amKeyProvider.getPrivateKey(keyAlias); try { boolean verified = jwtBuilderFactory.reconstruct(authId, SignedJwt.class).verify(privateKey); if (!verified) { throw new RestAuthException(Response.Status.BAD_REQUEST, "AuthId JWT Signature not valid"); } } catch (JwtRuntimeException e) { throw new RestAuthException(Response.Status.BAD_REQUEST, "Failed to parse JWT, " + e.getLocalizedMessage(), e); } } @Inject  AuthIdHelper(CoreServicesWrapper coreServicesWrapper, AMKeyProvider amKeyProvider,
            JwtBuilderFactory jwtBuilderFactory); }
AuthIdHelper { public void verifyAuthId(String realmDN, String authId) { String keyAlias = getKeyAlias(realmDN); PrivateKey privateKey = amKeyProvider.getPrivateKey(keyAlias); try { boolean verified = jwtBuilderFactory.reconstruct(authId, SignedJwt.class).verify(privateKey); if (!verified) { throw new RestAuthException(Response.Status.BAD_REQUEST, "AuthId JWT Signature not valid"); } } catch (JwtRuntimeException e) { throw new RestAuthException(Response.Status.BAD_REQUEST, "Failed to parse JWT, " + e.getLocalizedMessage(), e); } } @Inject  AuthIdHelper(CoreServicesWrapper coreServicesWrapper, AMKeyProvider amKeyProvider,
            JwtBuilderFactory jwtBuilderFactory); String createAuthId(LoginConfiguration loginConfiguration, AuthenticationContext authContext); SignedJwt reconstructAuthId(String authId); void verifyAuthId(String realmDN, String authId); }
AuthIdHelper { public void verifyAuthId(String realmDN, String authId) { String keyAlias = getKeyAlias(realmDN); PrivateKey privateKey = amKeyProvider.getPrivateKey(keyAlias); try { boolean verified = jwtBuilderFactory.reconstruct(authId, SignedJwt.class).verify(privateKey); if (!verified) { throw new RestAuthException(Response.Status.BAD_REQUEST, "AuthId JWT Signature not valid"); } } catch (JwtRuntimeException e) { throw new RestAuthException(Response.Status.BAD_REQUEST, "Failed to parse JWT, " + e.getLocalizedMessage(), e); } } @Inject  AuthIdHelper(CoreServicesWrapper coreServicesWrapper, AMKeyProvider amKeyProvider,
            JwtBuilderFactory jwtBuilderFactory); String createAuthId(LoginConfiguration loginConfiguration, AuthenticationContext authContext); SignedJwt reconstructAuthId(String authId); void verifyAuthId(String realmDN, String authId);  }