Keycloak ~ custom redirect_ The method of URI


In the process of integrating springboot with keycloak, for the interface that needs authorization, it will jump to keycloak to log in, and there is a redirect before it_ URI. After successful login, it will jump back to the client. However, there is no place to modify this address by default. We need to develop it manually. This is not very convenient.

Customize redirect_ URI

A rewrite beanpostprocessor to implement

public class KeycloackAuthenticationProcessingFilterPostProcessor implements BeanPostProcessor {

    private static final Logger logger = LoggerFactory.getLogger(KeycloackAuthenticationProcessingFilterPostProcessor.class);

    private void process(KeycloakAuthenticationProcessingFilter filter) {
        filter.setRequestAuthenticatorFactory(new SpringSecurityRequestAuthenticatorFactory() {
            public RequestAuthenticator createRequestAuthenticator(HttpFacade facade, HttpServletRequest request, KeycloakDeployment deployment, AdapterTokenStore tokenStore, int sslRedirectPort) {
                return new SpringSecurityRequestAuthenticator(facade, request, deployment, tokenStore, sslRedirectPort) {

                    protected OAuthRequestAuthenticator createOAuthAuthenticator() {
                        return new OAuthRequestAuthenticator(this, facade, deployment, sslRedirectPort, tokenStore) {

                            protected String getRequestUrl() {
                                return "http://localhost:8081/callback";


    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof KeycloakAuthenticationProcessingFilter) {
  "Injecting Custom handler...");
            process(((KeycloakAuthenticationProcessingFilter) bean));
        return bean;

Second, when there is no authorization, directly jump to the authorization system, and then observe the address redirect_ The URI has changed

Reference documents:

Recommended Today

Stack chain storage

Linked list implementation stack Create three files: stacklinked. H, stacklinked. C, stacklinkedtest. C stackLinked.h #ifndef STACK_LINKED_H_ #define STACK_LINKED_H_ #ifdef __GNUC__ #define DEPRECATED __attribute__( (deprecated) ) #elif defined(_MSC_VER) #define DEPRECATED __declspec( deprecated ) #else #define DEPRECATED #endif #ifndef PTOI #define PTOI( p ) ((int32_t)(int64_t)(p)) #endif #ifndef ITOP #define ITOP( i ) ((void *)(int64_t)(i)) #endif #define ADT […]