use of org.pac4j.oidc.config.OidcConfiguration in project cas by apereo.
the class DelegatedClientFactory method configureOidcClient.
/**
* Configure oidc client.
*
* @param properties the properties
*/
protected void configureOidcClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
pac4jProperties.getOidc().stream().filter(oidc -> StringUtils.isNotBlank(oidc.getId()) && StringUtils.isNotBlank(oidc.getSecret())).forEach(oidc -> {
final OidcClient client;
switch(oidc.getType().toUpperCase()) {
case "GOOGLE":
final OidcConfiguration cfg = getOidcConfigurationForClient(oidc, OidcConfiguration.class);
client = new GoogleOidcClient(cfg);
break;
case "AZURE":
final AzureAdOidcConfiguration azure = getOidcConfigurationForClient(oidc, AzureAdOidcConfiguration.class);
client = new AzureAdClient(new AzureAdOidcConfiguration(azure));
break;
case "KEYCLOAK":
final KeycloakOidcConfiguration keycfg = getOidcConfigurationForClient(oidc, KeycloakOidcConfiguration.class);
client = new KeycloakOidcClient(keycfg);
break;
case "GENERIC":
default:
final OidcConfiguration gencfg = getOidcConfigurationForClient(oidc, OidcConfiguration.class);
client = new OidcClient(gencfg);
break;
}
final int count = index.intValue();
if (StringUtils.isBlank(oidc.getClientName())) {
client.setName(client.getClass().getSimpleName() + count);
}
configureClient(client, oidc);
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
use of org.pac4j.oidc.config.OidcConfiguration in project pac4j by pac4j.
the class RunMitreIdOrg method getClient.
@Override
protected IndirectClient getClient() {
final OidcConfiguration configuration = new OidcConfiguration();
configuration.setClientId("acdf79d7-0129-4ba3-bc61-a52486cf82ff");
configuration.setSecret("ALhlPK5ONNGojjZvEiIgyNEUfX1MbAlDXT1dM0-pVQSa-IID5QMq-lEhlawRqejPZ8c70LBqfKyFL79tefmPb7k");
configuration.setDiscoveryURI("https://mitreid.org/.well-known/openid-configuration");
configuration.setPreferredJwsAlgorithm(JWSAlgorithm.parse("none"));
final OidcClient client = new OidcClient(configuration);
client.setCallbackUrl(PAC4J_URL);
return client;
}
use of org.pac4j.oidc.config.OidcConfiguration in project pac4j by pac4j.
the class RunOkta method getClient.
@Override
protected IndirectClient getClient() {
final OidcConfiguration configuration = new OidcConfiguration();
configuration.setClientId("ZuxDX1Gw2Kvx4gFyDNWC");
configuration.setSecret("77kjmDs94pA4UOVkeuYY7XyHnsDmSWoezrc3XZFU");
configuration.setDiscoveryURI("https://dev-425954.oktapreview.com/.well-known/openid-configuration");
final OidcClient client = new OidcClient(configuration);
client.setCallbackUrl(PAC4J_URL);
return client;
}
use of org.pac4j.oidc.config.OidcConfiguration in project ddf by codice.
the class OidcHandlerConfigurationImpl method createOidcConfiguration.
@VisibleForTesting
OidcConfiguration createOidcConfiguration(String idpType, String realm, String baseUri) {
OidcConfiguration configuration;
if ("Keycloak".equals(idpType)) {
KeycloakOidcConfiguration keycloakOidcConfiguration = new KeycloakOidcConfiguration();
keycloakOidcConfiguration.setRealm(realm);
keycloakOidcConfiguration.setBaseUri(baseUri);
configuration = keycloakOidcConfiguration;
} else if ("Azure".equals(idpType)) {
AzureAdOidcConfiguration azureAdOidcConfiguration = new AzureAdOidcConfiguration();
azureAdOidcConfiguration.setTenant(realm);
configuration = azureAdOidcConfiguration;
} else {
configuration = new OidcConfiguration();
}
return configuration;
}
use of org.pac4j.oidc.config.OidcConfiguration in project ddf by codice.
the class OidcHandler method getNormalizedToken.
/**
* Handler implementing OIDC authentication.
*
* @param request http request to obtain attributes from and to pass into any local filter chains
* required
* @param response http response to return http responses or redirects
* @param chain original filter chain (should not be called from your handler)
* @param resolve flag with true implying that credentials should be obtained, false implying
* return if no credentials are found.
* @return result of handling this request - status and optional tokens
* @throws AuthenticationFailureException
*/
@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, SecurityFilterChain chain, boolean resolve) throws AuthenticationFailureException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (httpRequest.getMethod().equals("HEAD")) {
return processHeadRequest(httpResponse);
}
LOGGER.debug("Doing Oidc authentication and authorization for path {}.", httpRequest.getContextPath());
JEESessionStore sessionStore = new JEESessionStore();
JEEContext jeeContext = new JEEContext(httpRequest, httpResponse, sessionStore);
StringBuffer requestUrlBuffer = httpRequest.getRequestURL();
requestUrlBuffer.append(httpRequest.getQueryString() == null ? "" : "?" + httpRequest.getQueryString());
String requestUrl = requestUrlBuffer.toString();
String ipAddress = httpRequest.getRemoteAddr();
OidcClient<OidcConfiguration> oidcClient = configuration.getOidcClient(requestUrl);
OidcCredentials credentials;
boolean isMachine = userAgentIsNotBrowser(httpRequest);
if (isMachine) {
LOGGER.debug("The Oidc Handler does not handle machine to machine requests. Continuing to other handlers.");
return noActionResult;
} else {
// check for Authorization Code Flow, Implicit Flow, or Hybrid Flow credentials
try {
credentials = getCredentialsFromRequest(oidcClient, jeeContext);
} catch (IllegalArgumentException e) {
LOGGER.debug(e.getMessage(), e);
LOGGER.error("Problem with the Oidc Handler's configuration. " + "Check the Oidc Handler configuration in the admin console.");
return noActionResult;
} catch (TechnicalException e) {
LOGGER.debug("Problem extracting Oidc credentials from incoming user request.", e);
return redirectForCredentials(oidcClient, jeeContext, requestUrl);
}
}
// if the request has credentials, process it
if (credentials != null && (credentials.getCode() != null || credentials.getAccessToken() != null || credentials.getIdToken() != null)) {
LOGGER.info("Oidc credentials found/retrieved. Saving to session and continuing filter chain.");
OidcAuthenticationToken token = new OidcAuthenticationToken(credentials, jeeContext, ipAddress);
HandlerResult handlerResult = new HandlerResultImpl(Status.COMPLETED, token);
handlerResult.setSource(SOURCE);
return handlerResult;
} else {
// the user agent request didn't have credentials, redirect and go get some
LOGGER.info("No credentials found on user-agent request. " + "Redirecting user-agent to IdP for credentials.");
return redirectForCredentials(oidcClient, jeeContext, requestUrl);
}
}
Aggregations