You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/05/01 17:10:30 UTC

[GitHub] [lucene-solr] madrob commented on a change in pull request #341: SOLR-12131: ExternalRoleRuleBasedAuthorizationPlugin

madrob commented on a change in pull request #341:
URL: https://github.com/apache/lucene-solr/pull/341#discussion_r418632788



##########
File path: solr/core/src/java/org/apache/solr/security/PrincipalWithUserRoles.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.solr.security;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.Set;
+
+import org.apache.http.util.Args;
+
+/**
+ * Type of Principal object that can contain also a list of roles the user has.
+ * One use case can be to keep track of user-role mappings in an Identity Server
+ * external to Solr and pass the information to Solr in a signed JWT token or in 
+ * another secure manner. The role information can then be used to authorize
+ * requests without the need to maintain or lookup what roles each user belongs to. 
+ */
+public class PrincipalWithUserRoles implements Principal, VerifiedUserRoles, Serializable {

Review comment:
       Could this class be `final`? Also, why Serializable?

##########
File path: solr/solr-ref-guide/src/rule-based-authorization-plugin.adoc
##########
@@ -64,6 +66,34 @@ There are several things defined in this example:
 <5> The 'admin' role has been defined, and it has permission to edit security settings.
 <6> The 'solr' user has been defined to the 'admin' role.
 
+=== Example for ExternalRoleRuleBasedAuthorizationPlugin
+This example `security.json` shows how an imagined `JWTAuthPlugin`, which pulls user and user roles from JWT claims, can work with the `ExternalRoleRuleBasedAuthorizationPlugin` plugin:

Review comment:
       s/imagined//, this exists, right?

##########
File path: solr/core/src/java/org/apache/solr/security/RuleBasedAuthorizationPluginBase.java
##########
@@ -0,0 +1,270 @@
+/*
+ * 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.solr.security;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.apache.solr.common.SpecProvider;
+import org.apache.solr.common.util.CommandOperation;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.common.util.ValidatingJsonMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.util.Collections.unmodifiableMap;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.solr.handler.admin.SecurityConfHandler.getListValue;
+
+/**
+ * Base class for rule based authorization plugins
+ */
+public abstract class RuleBasedAuthorizationPluginBase implements AuthorizationPlugin, ConfigEditablePlugin, SpecProvider {

Review comment:
       Is this largely a copy of the old RuleBasedAuthorizationPlugin? If you can let me know which parts were changed, it will be easier to review.

##########
File path: solr/core/src/java/org/apache/solr/security/PrincipalWithUserRoles.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.solr.security;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.Set;
+
+import org.apache.http.util.Args;
+
+/**
+ * Type of Principal object that can contain also a list of roles the user has.
+ * One use case can be to keep track of user-role mappings in an Identity Server
+ * external to Solr and pass the information to Solr in a signed JWT token or in 
+ * another secure manner. The role information can then be used to authorize
+ * requests without the need to maintain or lookup what roles each user belongs to. 
+ */
+public class PrincipalWithUserRoles implements Principal, VerifiedUserRoles, Serializable {
+  private static final long serialVersionUID = 4144666467522831388L;
+  private final String username;
+
+  private final Set<String> roles;
+
+  /**
+   * User principal with user name as well as one or more roles that he/she belong to
+   * @param username string with user name for user
+   * @param roles a set of roles that we know this user belongs to, or empty list for no roles
+   */
+  public PrincipalWithUserRoles(final String username, Set<String> roles) {
+    super();
+    Args.notNull(username, "User name");

Review comment:
       nit: prefer `Objects.requireNonNull`




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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org