001/* 002 * Copyright 2022 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.extrausermgt.authentication.oidc; 017 018import java.net.MalformedURLException; 019import java.net.URI; 020import java.util.Map; 021 022import org.apache.commons.lang3.StringUtils; 023 024import org.ametys.runtime.authentication.AccessDeniedException; 025 026import com.nimbusds.oauth2.sdk.Scope; 027import com.nimbusds.oauth2.sdk.id.Issuer; 028import com.nimbusds.openid.connect.sdk.OIDCScopeValue; 029 030/** 031 * Sign in through a OIDC application, using the OpenId Connect protocol. 032 */ 033public class GenericOIDCCredentialProvider extends AbstractOIDCCredentialProvider 034{ 035 @Override 036 protected void initUrisScope() throws AccessDeniedException 037 { 038 Map<String, Object> paramValues = getParameterValues(); 039 try 040 { 041 _authUri = URI.create((String) paramValues.get("authentication.oidc.authUri")); 042 _tokenEndpointUri = URI.create((String) paramValues.get("authentication.oidc.tokenEndpointUri")); 043 _iss = new Issuer((String) paramValues.get("authentication.oidc.issuer")); 044 _jwkSetURL = URI.create((String) paramValues.get("authentication.oidc.jwkSetURL")).toURL(); 045 _userInfoEndpoint = URI.create((String) paramValues.get("authentication.oidc.userInfoEndpoint")); 046 String endSession = (String) paramValues.get("authentication.oidc.endSessionEndpoint"); 047 if (StringUtils.isNotBlank(endSession)) 048 { 049 _endSessionEndPoint = URI.create(endSession); 050 } 051 } 052 catch (MalformedURLException e) 053 { 054 getLogger().error("Encountered a problem when creating the jwkSetURL", e); 055 throw new AccessDeniedException("Encountered a problem when creating the jwkSetURL"); 056 } 057 058 _scope = Scope.parse((String) paramValues.get("authentication.oidc.scopes")); 059 _scope.add(OIDCScopeValue.OPENID); 060 } 061}