You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/07/13 16:56:53 UTC
[GitHub] [druid] jihoonson commented on a change in pull request #10106: Add validation for authenticator and authorizer name
jihoonson commented on a change in pull request #10106:
URL: https://github.com/apache/druid/pull/10106#discussion_r453791703
##########
File path: extensions-core/druid-basic-security/src/test/java/org/apache/druid/security/basic/authentication/endpoint/BasicAuthenticatorResourceTest.java
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.basic.authentication.endpoint;
+
+import org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorCredentialUpdate;
+import org.apache.druid.server.security.AuthValidator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.StandardCharsets;
+
+@RunWith(MockitoJUnitRunner.class)
+public class BasicAuthenticatorResourceTest
+{
+ private static final String AUTHENTICATOR_NAME = "AUTHENTICATOR_NAME";
+ private static final String INVALID_AUTHENTICATOR_NAME = "INVALID_AUTHENTICATOR_NAME";
+ private static final String USER_NAME = "USER_NAME";
+ private static final byte[] SERIALIZED_USER_MAP = "SERIALIZED_USER_MAP".getBytes(StandardCharsets.UTF_8);
+ @Mock(answer = Answers.RETURNS_MOCKS)
+ private BasicAuthenticatorResourceHandler handler;
+ @Mock
+ private AuthValidator authValidator;
+ @Mock
+ private HttpServletRequest req;
+ @Mock
+ private BasicAuthenticatorCredentialUpdate update;
+
+ private BasicAuthenticatorResource target;
+
+ @Before
+ public void setUp()
+ {
+ Mockito.doThrow(IllegalArgumentException.class)
+ .when(authValidator)
+ .validateAuthenticatorName(INVALID_AUTHENTICATOR_NAME);
Review comment:
Why do we mock `authValidator` here? It doesn't seem hard to use the real method. I would suggest to use the real method in that case since we can catch potential side effects easily if we modify the logic of `authValidator`.
##########
File path: server/src/main/java/org/apache/druid/server/security/AuthValidator.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.server.security;
+
+import org.apache.druid.common.utils.IdUtils;
+
+/**
+ * Utility functions to validate the an authorizer.
+ */
+public class AuthValidator
+{
+ private static final String AUTHORIZER_NAME = "authorizerName";
+ private static final String AUTHENTICATOR_NAME = "authenticatorName";
+
+ /**
+ * Validates the provided authorizerName.
+ *
+ * @param authorizerName the name of the authorizer.
+ * @throws IllegalArgumentException on invalid authorizer names.
+ */
+ public void validateAuthorizerName(String authorizerName)
Review comment:
Why are these methods not static? It doesn't seem to need to inject this class if they are static.
##########
File path: extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/authentication/endpoint/BasicAuthenticatorResource.java
##########
@@ -102,6 +106,7 @@ public Response getAllUsers(
@PathParam("authenticatorName") final String authenticatorName
)
{
+ authValidator.validateAuthenticatorName(authenticatorName);
Review comment:
Can this check be added in `BasicSecurityResourceFilter` instead of adding it everywhere? `BasicSecurityResourceFilter` is used by both `BasicAuthenticationResource` and `BasicAuthorizerResource`.
##########
File path: extensions-core/druid-basic-security/src/test/java/org/apache/druid/security/basic/authentication/endpoint/BasicAuthenticatorResourceTest.java
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.basic.authentication.endpoint;
+
+import org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorCredentialUpdate;
+import org.apache.druid.server.security.AuthValidator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.StandardCharsets;
+
+@RunWith(MockitoJUnitRunner.class)
+public class BasicAuthenticatorResourceTest
+{
+ private static final String AUTHENTICATOR_NAME = "AUTHENTICATOR_NAME";
+ private static final String INVALID_AUTHENTICATOR_NAME = "INVALID_AUTHENTICATOR_NAME";
+ private static final String USER_NAME = "USER_NAME";
+ private static final byte[] SERIALIZED_USER_MAP = "SERIALIZED_USER_MAP".getBytes(StandardCharsets.UTF_8);
+ @Mock(answer = Answers.RETURNS_MOCKS)
+ private BasicAuthenticatorResourceHandler handler;
+ @Mock
+ private AuthValidator authValidator;
+ @Mock
+ private HttpServletRequest req;
+ @Mock
+ private BasicAuthenticatorCredentialUpdate update;
+
+ private BasicAuthenticatorResource target;
+
+ @Before
+ public void setUp()
+ {
+ Mockito.doThrow(IllegalArgumentException.class)
+ .when(authValidator)
+ .validateAuthenticatorName(INVALID_AUTHENTICATOR_NAME);
Review comment:
Same for `BasicAuthorizerResourceFilter`.
----------------------------------------------------------------
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: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org