Infinite loop redirection with OIDC and MITREid server

313 views
Skip to first unread message

Tam Nguyen Van

unread,
Aug 31, 2017, 5:40:46 AM8/31/17
to Pac4j users mailing list
Hello,

I am doing an demo of SSO using OpenID Connect protocol. I use MITREid Connect Server as OP (IdP, OpenID Provider). I use spring boot to implement client, I use spring-security-pac4j and pac4j-oidc. Below is the dependencies I added to pom:
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>spring-security-pac4j</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-oidc</artifactId>
<version>2.1.0</version>
</dependency>
 
Below is my configuration for client:
    @Bean
    public Config config() {
        final OidcConfiguration oidcConfiguration = new OidcConfiguration();
        oidcConfiguration.setClientId("client-id-1");
        oidcConfiguration.setSecret("secret-1");
        oidcConfiguration.setScope("openid email profile");
        oidcConfiguration.setResponseType("id_token token");
        oidcConfiguration.setUseNonce(true);
        oidcConfiguration.setDiscoveryURI("https://192.168.7.90:8443/openid-connect-server-webapp/.well-known/openid-configuration");

        final OidcClient oidcClient = new OidcClient(oidcConfiguration);
        oidcClient.setIncludeClientNameInCallbackUrl(false);
        final Clients clients = new Clients("https://192.168.7.40:8443/", oidcClient);
        final Config config = new Config(clients);

        return config;
    }



I got an infinite loop redirection after authenticate and consent. Meaning after authentication and consent on OP, OP redirect me to client but client redirect me to OP again instead of going to protected page. It makes a loop of redirection. Anyone can tell me what I did wrong in my demo?

Any help is appreciated. Thanks.

Jérôme LELEU

unread,
Sep 2, 2017, 2:56:45 AM9/2/17
to Tam Nguyen Van, Pac4j users mailing list
Hi,

The callback URL you use: final Clients clients = new Clients("https://192.168.7.40:8443/", oidcClient); should certainly be: final Clients clients = new Clients("https://192.168.7.40:8443/callback", oidcClient);

Thanks.
Best regards,
Jérôme


--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tam Nguyen Van

unread,
Sep 5, 2017, 4:49:25 AM9/5/17
to Pac4j users mailing list, tam.n...@ntq-solution.com.vn
Why it should certainly be callback? I tried but still encountered the same problem. 
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users...@googlegroups.com.

Tam Nguyen Van

unread,
Sep 6, 2017, 12:03:53 AM9/6/17
to Pac4j users mailing list
// This is my Security Config

@EnableWebSecurity
public class SecurityConfig {

@Configuration
@Order(2)
public static class OidcWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

@Autowired
private Config config;

protected void configure(final HttpSecurity http) throws Exception {

final SecurityFilter filter = new SecurityFilter(config, "OidcClient");
final CallbackFilter callbackFilter = new CallbackFilter(config);
callbackFilter.setMultiProfile(true);

http
.antMatcher("/**")
.addFilterBefore(filter, BasicAuthenticationFilter.class)
.addFilterBefore(callbackFilter, BasicAuthenticationFilter.class)
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
}
}
}

Jérôme LELEU

unread,
Sep 6, 2017, 2:52:51 AM9/6/17
to Tam Nguyen Van, Pac4j users mailing list
Hi,

Indeed, there is an issue in your configuration: the security filter is triggered BEFORE the callback filter, so you can never finish the login process as the security always kicks in before.

Switch the two filters in order: first, the callbackFilter then the filter.

Thanks.
Best regards,
Jérôme


--
You received this message because you are subscribed to the Google Groups "Pac4j users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pac4j-users+unsubscribe@googlegroups.com.

Tam Nguyen Van

unread,
Sep 6, 2017, 5:36:57 AM9/6/17
to Pac4j users mailing list
Thanks a lot, Sir!
Reply all
Reply to author
Forward
0 new messages