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.net.URL; 021import java.util.Map; 022 023import org.ametys.runtime.authentication.AccessDeniedException; 024 025import com.nimbusds.oauth2.sdk.Scope; 026import com.nimbusds.oauth2.sdk.id.Issuer; 027import com.nimbusds.openid.connect.sdk.OIDCScopeValue; 028 029/** 030 * Sign in through a OIDC application, using the OpenId Connect protocol. 031 */ 032public class GenericOIDCCredentialProvider extends AbstractOIDCCredentialProvider 033{ 034 @Override 035 protected void initUrisScope() throws AccessDeniedException 036 { 037 Map<String, Object> paramValues = getParameterValues(); 038 try 039 { 040 _authUri = URI.create((String) paramValues.get("authentication.oidc.authUri")); 041 _tokenEndpointUri = URI.create((String) paramValues.get("authentication.oidc.tokenEndpointUri")); 042 _iss = new Issuer((String) paramValues.get("authentication.oidc.issuer")); 043 _jwkSetURL = new URL((String) paramValues.get("authentication.oidc.jwkSetURL")); 044 _userInfoEndpoint = URI.create((String) paramValues.get("authentication.oidc.userInfoEndpoint")); 045 } 046 catch (MalformedURLException e) 047 { 048 getLogger().error("Encountered a problem when creating the jwkSetURL", e); 049 throw new AccessDeniedException("Encountered a problem when creating the jwkSetURL"); 050 } 051 052 _scope = Scope.parse((String) paramValues.get("authentication.oidc.scopes")); 053 _scope.add(OIDCScopeValue.OPENID); 054 } 055}