@Test public void shouldForwardAuthInfoName() throws CertificateEncodingException, IOException { ForwardAuthInfo authInfo = new ForwardAuthInfo(); authInfo.setHeaders("X-TEST"); authInfo.setField("preferred_username"); config.getForwardAuthInfo().add(authInfo); token.setPreferredUsername("ABC"); String encoded = generateAndSerializeToken(); apiRequest.getHeaders().put("Authorization", "Bearer " + encoded); keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain); verify(mChain).doApply(apiRequest); Assert.assertEquals("ABC", apiRequest.getHeaders().get("X-TEST")); }
@Override protected void doApply(final ApiRequest request, final IPolicyContext context, final KeycloakOauthConfigBean config, final IPolicyChain<ApiRequest> chain) { final String rawToken = getRawAuthToken(request); final Holder<Boolean> successStatus = new Holder<>(true); if (rawToken == null) { if (config.getRequireOauth()) { doFailure(successStatus, chain, failureFactory.noAuthenticationProvided(context)); } else { chain.doApply(request); } } else if (doTokenAuth(successStatus, request, context, config, chain, rawToken).getValue()) { if (config.getRequireTransportSecurity() && !request.isTransportSecure()) { if (config.getBlacklistUnsafeTokens()) { blacklistToken(context, rawToken, new IAsyncResultHandler<Void>() { @Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { } } }); } doFailure(successStatus, chain, failureFactory.noTransportSecurity(context)); return; } if (config.getBlacklistUnsafeTokens()) { isBlacklistedToken(context, rawToken, new IAsyncResultHandler<Boolean>() { @Override public void handle(IAsyncResult<Boolean> result) { if (result.isError()) { throwError(successStatus, chain, result.getError()); } else if (result.getResult()) { doFailure(successStatus, chain, failureFactory.blacklistedToken(context)); } else { chain.doApply(request); } } }); } else { if (successStatus.getValue()) { chain.doApply(request); } } } }
KeycloakOauthPolicy extends AbstractMappedPolicy<KeycloakOauthConfigBean> { @Override protected void doApply(final ApiRequest request, final IPolicyContext context, final KeycloakOauthConfigBean config, final IPolicyChain<ApiRequest> chain) { final String rawToken = getRawAuthToken(request); final Holder<Boolean> successStatus = new Holder<>(true); if (rawToken == null) { if (config.getRequireOauth()) { doFailure(successStatus, chain, failureFactory.noAuthenticationProvided(context)); } else { chain.doApply(request); } } else if (doTokenAuth(successStatus, request, context, config, chain, rawToken).getValue()) { if (config.getRequireTransportSecurity() && !request.isTransportSecure()) { if (config.getBlacklistUnsafeTokens()) { blacklistToken(context, rawToken, new IAsyncResultHandler<Void>() { @Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { } } }); } doFailure(successStatus, chain, failureFactory.noTransportSecurity(context)); return; } if (config.getBlacklistUnsafeTokens()) { isBlacklistedToken(context, rawToken, new IAsyncResultHandler<Boolean>() { @Override public void handle(IAsyncResult<Boolean> result) { if (result.isError()) { throwError(successStatus, chain, result.getError()); } else if (result.getResult()) { doFailure(successStatus, chain, failureFactory.blacklistedToken(context)); } else { chain.doApply(request); } } }); } else { if (successStatus.getValue()) { chain.doApply(request); } } } } }
KeycloakOauthPolicy extends AbstractMappedPolicy<KeycloakOauthConfigBean> { @Override protected void doApply(final ApiRequest request, final IPolicyContext context, final KeycloakOauthConfigBean config, final IPolicyChain<ApiRequest> chain) { final String rawToken = getRawAuthToken(request); final Holder<Boolean> successStatus = new Holder<>(true); if (rawToken == null) { if (config.getRequireOauth()) { doFailure(successStatus, chain, failureFactory.noAuthenticationProvided(context)); } else { chain.doApply(request); } } else if (doTokenAuth(successStatus, request, context, config, chain, rawToken).getValue()) { if (config.getRequireTransportSecurity() && !request.isTransportSecure()) { if (config.getBlacklistUnsafeTokens()) { blacklistToken(context, rawToken, new IAsyncResultHandler<Void>() { @Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { } } }); } doFailure(successStatus, chain, failureFactory.noTransportSecurity(context)); return; } if (config.getBlacklistUnsafeTokens()) { isBlacklistedToken(context, rawToken, new IAsyncResultHandler<Boolean>() { @Override public void handle(IAsyncResult<Boolean> result) { if (result.isError()) { throwError(successStatus, chain, result.getError()); } else if (result.getResult()) { doFailure(successStatus, chain, failureFactory.blacklistedToken(context)); } else { chain.doApply(request); } } }); } else { if (successStatus.getValue()) { chain.doApply(request); } } } }  }
KeycloakOauthPolicy extends AbstractMappedPolicy<KeycloakOauthConfigBean> { @Override protected void doApply(final ApiRequest request, final IPolicyContext context, final KeycloakOauthConfigBean config, final IPolicyChain<ApiRequest> chain) { final String rawToken = getRawAuthToken(request); final Holder<Boolean> successStatus = new Holder<>(true); if (rawToken == null) { if (config.getRequireOauth()) { doFailure(successStatus, chain, failureFactory.noAuthenticationProvided(context)); } else { chain.doApply(request); } } else if (doTokenAuth(successStatus, request, context, config, chain, rawToken).getValue()) { if (config.getRequireTransportSecurity() && !request.isTransportSecure()) { if (config.getBlacklistUnsafeTokens()) { blacklistToken(context, rawToken, new IAsyncResultHandler<Void>() { @Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { } } }); } doFailure(successStatus, chain, failureFactory.noTransportSecurity(context)); return; } if (config.getBlacklistUnsafeTokens()) { isBlacklistedToken(context, rawToken, new IAsyncResultHandler<Boolean>() { @Override public void handle(IAsyncResult<Boolean> result) { if (result.isError()) { throwError(successStatus, chain, result.getError()); } else if (result.getResult()) { doFailure(successStatus, chain, failureFactory.blacklistedToken(context)); } else { chain.doApply(request); } } }); } else { if (successStatus.getValue()) { chain.doApply(request); } } } }   }
KeycloakOauthPolicy extends AbstractMappedPolicy<KeycloakOauthConfigBean> { @Override protected void doApply(final ApiRequest request, final IPolicyContext context, final KeycloakOauthConfigBean config, final IPolicyChain<ApiRequest> chain) { final String rawToken = getRawAuthToken(request); final Holder<Boolean> successStatus = new Holder<>(true); if (rawToken == null) { if (config.getRequireOauth()) { doFailure(successStatus, chain, failureFactory.noAuthenticationProvided(context)); } else { chain.doApply(request); } } else if (doTokenAuth(successStatus, request, context, config, chain, rawToken).getValue()) { if (config.getRequireTransportSecurity() && !request.isTransportSecure()) { if (config.getBlacklistUnsafeTokens()) { blacklistToken(context, rawToken, new IAsyncResultHandler<Void>() { @Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { } } }); } doFailure(successStatus, chain, failureFactory.noTransportSecurity(context)); return; } if (config.getBlacklistUnsafeTokens()) { isBlacklistedToken(context, rawToken, new IAsyncResultHandler<Boolean>() { @Override public void handle(IAsyncResult<Boolean> result) { if (result.isError()) { throwError(successStatus, chain, result.getError()); } else if (result.getResult()) { doFailure(successStatus, chain, failureFactory.blacklistedToken(context)); } else { chain.doApply(request); } } }); } else { if (successStatus.getValue()) { chain.doApply(request); } } } }    }