You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/05/24 16:24:29 UTC

[GitHub] [incubator-iotdb] xingtanzjr commented on a change in pull request #1255: Feature/iotdb 700 add openid

xingtanzjr commented on a change in pull request #1255:
URL: https://github.com/apache/incubator-iotdb/pull/1255#discussion_r429652777



##########
File path: server/src/main/java/org/apache/iotdb/db/auth/authorizer/OpenIdAuthorizer.java
##########
@@ -0,0 +1,248 @@
+/*
+ * 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.iotdb.db.auth.authorizer;
+
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.jwk.RSAKey;
+import com.nimbusds.oauth2.sdk.ParseException;
+import com.nimbusds.oauth2.sdk.util.JSONObjectUtils;
+import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.JwtException;
+import io.jsonwebtoken.Jwts;
+import net.minidev.json.JSONArray;
+import net.minidev.json.JSONObject;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.auth.entity.Role;
+import org.apache.iotdb.db.auth.entity.User;
+import org.apache.iotdb.db.auth.role.LocalFileRoleManager;
+import org.apache.iotdb.db.auth.user.LocalFileUserManager;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.interfaces.RSAPublicKey;
+import java.util.*;
+
+/**
+ * Uses an OpenID Connect provider for Authorization / Authentication.
+ */
+public class OpenIdAuthorizer extends BasicAuthorizer {
+
+    private static final Logger logger = LoggerFactory.getLogger(OpenIdAuthorizer.class);
+    public static final String IOTDB_ADMIN_ROLE_NAME = "iotdb_admin";
+
+    private static IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+
+    private RSAPublicKey providerKey;
+
+    /** Stores all claims to the respective user */
+    private Map<String, Claims> loggedClaims = new HashMap<>();
+
+    public OpenIdAuthorizer() throws AuthException, ParseException, IOException, URISyntaxException {
+        this(config.getOpenIdProviderUrl());
+    }
+
+    OpenIdAuthorizer(JSONObject jwk) throws AuthException, URISyntaxException, ParseException, IOException {
+        super(new LocalFileUserManager(config.getSystemDir() + File.separator + "users"),
+                new LocalFileRoleManager(config.getSystemDir() + File.separator + "roles"));
+        try {
+            providerKey = RSAKey.parse(jwk).toRSAPublicKey();
+        } catch (java.text.ParseException | JOSEException e) {
+            throw new AuthException("Unable to get OIDC Provider Key from JWK " +  jwk.toString(), e);
+        }
+        logger.info("Initialized with providerKey: {}", providerKey);
+    }
+
+    OpenIdAuthorizer(String providerUrl) throws AuthException, URISyntaxException, ParseException, IOException {
+        this(getJWKfromProvider(providerUrl));
+    }
+
+    private static JSONObject getJWKfromProvider(String providerUrl) throws URISyntaxException, IOException, ParseException, AuthException {
+        if (providerUrl == null) {
+            throw new IllegalArgumentException("OpenID Connect Provider URI must be given!");
+        }
+
+        //

Review comment:
       Let's remove empty comment here : )




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org