nozjkoitop commented on code in PR #18778: URL: https://github.com/apache/druid/pull/18778#discussion_r3272494061
########## extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/RoleBasedAuthGen.java: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.security.pac4j; + +import com.nimbusds.jwt.JWT; +import com.nimbusds.jwt.JWTClaimsSet; +import com.nimbusds.jwt.JWTParser; +import com.nimbusds.oauth2.sdk.token.AccessToken; +import org.apache.druid.java.util.common.logger.Logger; +import org.pac4j.core.authorization.generator.AuthorizationGenerator; +import org.pac4j.core.context.WebContext; +import org.pac4j.core.context.session.SessionStore; +import org.pac4j.core.profile.UserProfile; +import org.pac4j.oidc.profile.OidcProfile; + +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class RoleBasedAuthGen implements AuthorizationGenerator +{ + + private static final Logger LOG = new Logger(RoleBasedAuthGen.class); + + private final String roleClaimPath; // dot separated path to roles claim in the ID token + + public RoleBasedAuthGen(String roleClaimPath) + { + this.roleClaimPath = roleClaimPath; + } + + @Override + public Optional<UserProfile> generate(WebContext context, SessionStore sessionStore, UserProfile profile) + { + if (profile == null) { + return Optional.empty(); + } + + if (!(profile instanceof OidcProfile)) { + return Optional.of(profile); + } + + final AccessToken accessToken = ((OidcProfile) profile).getAccessToken(); Review Comment: Addressed. Docs updated, ID token claim retrieval added -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
