Search in sources :

Example 1 with OIDCAuthenticationRequestFactory

use of org.obiba.oidc.utils.OIDCAuthenticationRequestFactory in project obiba-commons by obiba.

the class OIDCLoginFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    J2EContext context = new J2EContext(request, response);
    String provider = OIDCHelper.extractProviderName(context, providerParameter);
    if (Strings.isNullOrEmpty(provider)) {
        log.error("No ID provider could be identified.");
    } else {
        try {
            OIDCConfiguration config = oidcConfigurationProvider.getConfiguration(provider);
            if (config == null)
                throw new OIDCException("No OIDC configuration could be found: " + provider);
            OIDCAuthenticationRequestFactory factory = new OIDCAuthenticationRequestFactory(makeCallbackURL(provider));
            AuthenticationRequest authRequest = factory.create(config);
            if (oidcSessionManager != null) {
                OIDCSession session = makeSession(context, authRequest);
                oidcSessionManager.saveSession(session);
            }
            response.sendRedirect(authRequest.toURI().toString());
        } catch (OIDCException e) {
            log.error("OIDC login request to '{}' failed.", provider, e);
            throw e;
        }
    }
    filterChain.doFilter(request, response);
}
Also used : J2EContext(org.obiba.oidc.web.J2EContext) OIDCAuthenticationRequestFactory(org.obiba.oidc.utils.OIDCAuthenticationRequestFactory) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest)

Example 2 with OIDCAuthenticationRequestFactory

use of org.obiba.oidc.utils.OIDCAuthenticationRequestFactory in project obiba-commons by obiba.

the class OIDCTest method test.

@Test
@Ignore
public void test() throws IOException, URISyntaxException, ParseException {
    KeycloakOIDCConfiguration config = new KeycloakOIDCConfiguration();
    config.setClientId("opal");
    config.setBaseUri("http://localhost:8899/auth");
    config.setRealm("obiba");
    OIDCAuthenticationRequestFactory factory = new OIDCAuthenticationRequestFactory("https://opal-demo.obiba.org/auth/callback");
    URI authReqURI = factory.create(config).toURI();
    System.out.println(authReqURI);
}
Also used : OIDCAuthenticationRequestFactory(org.obiba.oidc.utils.OIDCAuthenticationRequestFactory) URI(java.net.URI) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

OIDCAuthenticationRequestFactory (org.obiba.oidc.utils.OIDCAuthenticationRequestFactory)2 AuthenticationRequest (com.nimbusds.openid.connect.sdk.AuthenticationRequest)1 URI (java.net.URI)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 J2EContext (org.obiba.oidc.web.J2EContext)1