<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-forward-container">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <a moz-do-not-send="true"
href="http://stackoverflow.com/questions/33543672/keycloak-redirects-me-to-my-index-url-instead-of-to-the-requested-one">StackOverflow

        link to the question</a><br>
      <br>
      I'm using Keycloak server (v 1.5.1) to perform an open-id-connect
      like authentication to my service. I've set up a basic web
      application which has two urls, the */index.html* one and other
      one called /hello. I use Spring security, Spring boot and Spring
      MVC for all of that. That's my pom.xml configuration:<br>
      <br>
      <br>
          &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>
          &lt;project xmlns=<a moz-do-not-send="true"
        class="moz-txt-link-rfc2396E"
        href="http://maven.apache.org/POM/4.0.0">"http://maven.apache.org/POM/4.0.0"</a>
      xmlns:xsi=<a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
        href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a><br>
              xsi:schemaLocation=<a moz-do-not-send="true"
        class="moz-txt-link-rfc2396E"
href="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">"http://maven.apache.org/POM/4.0.0

        http://maven.apache.org/xsd/maven-4.0.0.xsd"</a>&gt;<br>
              &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br>
          <br>
              &lt;groupId&gt;com.keycloaktes&lt;/groupId&gt;<br>
              &lt;artifactId&gt;keycloaktes&lt;/artifactId&gt;<br>
              &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br>
              &lt;packaging&gt;jar&lt;/packaging&gt;<br>
          <br>
              &lt;name&gt;demo&lt;/name&gt;<br>
              &lt;description&gt;Demo project for Spring
      Boot&lt;/description&gt;<br>
          <br>
              &lt;parent&gt;<br>
                 
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>
                 
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>
                  &lt;version&gt;1.2.7.RELEASE&lt;/version&gt;<br>
                  &lt;relativePath /&gt;<br>
              &lt;/parent&gt;<br>
          <br>
              &lt;properties&gt;<br>
                 
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;<br>
                  &lt;java.version&gt;1.7&lt;/java.version&gt;<br>
              &lt;/properties&gt;<br>
          <br>
              &lt;dependencies&gt;<br>
                  &lt;dependency&gt;<br>
                     
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>
                     
      &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;<br>
                  &lt;/dependency&gt;<br>
          <br>
                  &lt;dependency&gt;<br>
                     
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>
                     
      &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>
                  &lt;/dependency&gt;<br>
          <br>
                  &lt;dependency&gt;<br>
                     
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>
                     
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;<br>
                      &lt;scope&gt;test&lt;/scope&gt;<br>
                  &lt;/dependency&gt;<br>
          <br>
                  &lt;dependency&gt;<br>
                      &lt;groupId&gt;org.keycloak&lt;/groupId&gt;<br>
                     
      &lt;artifactId&gt;keycloak-spring-security-adapter&lt;/artifactId&gt;<br>
                      &lt;version&gt;1.5.1.Final&lt;/version&gt;<br>
                  &lt;/dependency&gt;<br>
          <br>
                  &lt;dependency&gt;<br>
                      &lt;groupId&gt;org.keycloak&lt;/groupId&gt;<br>
                     
      &lt;artifactId&gt;keycloak-tomcat8-adapter&lt;/artifactId&gt;<br>
                      &lt;version&gt;1.5.1.Final&lt;/version&gt;<br>
                  &lt;/dependency&gt;<br>
          <br>
              &lt;/dependencies&gt;<br>
          <br>
          <br>
              &lt;build&gt;<br>
                  &lt;plugins&gt;<br>
                      &lt;plugin&gt;<br>
                         
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>
                         
      &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;<br>
                      &lt;/plugin&gt;<br>
                  &lt;/plugins&gt;<br>
              &lt;/build&gt;<br>
          <br>
          <br>
          &lt;/project&gt;<br>
      <br>
      The issue comes when I address to /hello url when not logged in,
      the keycloak login screen shows properly, but instead of
      performing a redirection to /hello after successful login, it does
      it to my /index.html page. That's how I've configured the security
      adapter:<br>
      <br>
      <br>
      &lt;!-- language: lang-java --&gt;<br>
      <br>
          @Configuration<br>
          @EnableWebSecurity<br>
          @ComponentScan(basePackageClasses =
      KeycloakSecurityComponents.class)<br>
          public class SecurityConfig extends
      KeycloakWebSecurityConfigurerAdapter {<br>
          <br>
              @Autowired<br>
              public void configureGlobal(AuthenticationManagerBuilder
      auth)<br>
                      throws Exception {<br>
                 
      auth.authenticationProvider(keycloakAuthenticationProvider());<br>
              }<br>
          <br>
              /**<br>
               * Defines the session authentication strategy.<br>
               */<br>
              @Bean<br>
              @Override<br>
              protected SessionAuthenticationStrategy
      sessionAuthenticationStrategy() {<br>
                  return new RegisterSessionAuthenticationStrategy(<br>
                          new SessionRegistryImpl());<br>
              }<br>
          <br>
              @Bean<br>
              public FilterRegistrationBean
      keycloakAuthenticationProcessingFilterRegistrationBean(<br>
                      KeycloakAuthenticationProcessingFilter filter) {<br>
                  FilterRegistrationBean registrationBean = new
      FilterRegistrationBean(<br>
                          filter);<br>
                  registrationBean.setEnabled(false);<br>
                  return registrationBean;<br>
              }<br>
          <br>
              @Bean<br>
              public FilterRegistrationBean
      keycloakPreAuthActionsFilterRegistrationBean(<br>
                      KeycloakPreAuthActionsFilter filter) {<br>
                  FilterRegistrationBean registrationBean = new
      FilterRegistrationBean(<br>
                          filter);<br>
                  registrationBean.setEnabled(false);<br>
                  return registrationBean;<br>
              }<br>
          <br>
              @Override<br>
              protected void configure(HttpSecurity http) throws
      Exception {<br>
                  super.configure(http);<br>
                 
      http.authorizeRequests().antMatchers("/*").hasRole("ADMIN")<br>
                          .anyRequest().permitAll();<br>
                  http.csrf().disable();<br>
              }<br>
          }<br>
      <br>
      I've been trying enabling both the
      `KeycloakAuthenticationProcessingFilter` and
      `KeycloakPreAuthActionsFilter`, but result keeps the same. Does
      anybody know how to solve the issue?<br>
    </div>
    <br>
  </body>
</html>