Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #8615] fix DeleteUserSubCommand command failed when acl2.0 authentication enabled and authorization disabled #8616

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.rocketmq.auth.authorization.context.AuthorizationContext;
import org.apache.rocketmq.auth.authorization.manager.AuthorizationMetadataManager;
import org.apache.rocketmq.auth.authorization.manager.AuthorizationMetadataManagerImpl;
import org.apache.rocketmq.auth.authorization.provider.AuthorizationDisabledMetadataProvider;
import org.apache.rocketmq.auth.authorization.provider.AuthorizationMetadataProvider;
import org.apache.rocketmq.auth.authorization.provider.AuthorizationProvider;
import org.apache.rocketmq.auth.authorization.provider.DefaultAuthorizationProvider;
Expand Down Expand Up @@ -79,6 +80,9 @@ public static AuthorizationMetadataProvider getMetadataProvider(AuthConfig confi
}
return computeIfAbsent(METADATA_PROVIDER_PREFIX + config.getConfigName(), key -> {
try {
if (!config.isAuthorizationEnabled()) {
return AuthorizationDisabledMetadataProvider.INSTANCE;
}
if (StringUtils.isBlank(config.getAuthorizationMetadataProvider())) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.rocketmq.auth.authorization.provider;

import org.apache.rocketmq.auth.authentication.model.Subject;
import org.apache.rocketmq.auth.authorization.model.Acl;
import org.apache.rocketmq.auth.config.AuthConfig;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public final class AuthorizationDisabledMetadataProvider implements AuthorizationMetadataProvider {
public final static AuthorizationDisabledMetadataProvider INSTANCE = new AuthorizationDisabledMetadataProvider();

private AuthorizationDisabledMetadataProvider() {
}

@Override
public void initialize(AuthConfig authConfig, Supplier<?> metadataService) {
}

@Override
public void shutdown() {
}

@Override
public CompletableFuture<Void> createAcl(Acl acl) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> deleteAcl(Subject subject) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Void> updateAcl(Acl acl) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Acl> getAcl(Subject subject) {
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<List<Acl>> listAcl(String subjectFilter, String resourceFilter) {
return CompletableFuture.completedFuture(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public void deleteUser() {
this.authenticationMetadataManager.deleteUser("no_user").join();
}

@Test
public void deleteUserIfAuthorizationDisabled() {
if (MixAll.isMac()) {
return;
}
this.authConfig.setAuthorizationEnabled(false);
this.authenticationMetadataManager = AuthenticationFactory.getMetadataManager(this.authConfig);
this.authenticationMetadataManager.deleteUser("no_user").join();
}

@Test
public void getUser() {
if (MixAll.isMac()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.rocketmq.auth.authorization.provider;

import org.apache.rocketmq.auth.authentication.model.User;
import org.apache.rocketmq.auth.authorization.model.Acl;
import org.apache.rocketmq.auth.config.AuthConfig;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
import java.util.concurrent.CompletableFuture;

public class AuthorizationDisabledMetadataProviderTest {

private AuthorizationDisabledMetadataProvider authorizationDisabledMetadataProvider;

@Before
public void setUp() throws Exception {
this.authorizationDisabledMetadataProvider = AuthorizationDisabledMetadataProvider.INSTANCE;
this.authorizationDisabledMetadataProvider.initialize(new AuthConfig(), null);
}

@After
public void tearDown() throws Exception {
this.authorizationDisabledMetadataProvider.shutdown();
}

@Test
public void createAcl() {
CompletableFuture<Void> future = this.authorizationDisabledMetadataProvider.createAcl(new Acl());
Assert.assertTrue(future.isDone());
}

@Test
public void deleteAcl() {
CompletableFuture<Void> future = this.authorizationDisabledMetadataProvider.deleteAcl(User.of("username"));
Assert.assertTrue(future.isDone());
}

@Test
public void updateAcl() {
CompletableFuture<Void> future = this.authorizationDisabledMetadataProvider.updateAcl(new Acl());
Assert.assertTrue(future.isDone());
}

@Test
public void getAcl() {
CompletableFuture<Acl> future = this.authorizationDisabledMetadataProvider.getAcl(User.of("username"));
Assert.assertTrue(future.isDone());
Assert.assertNull(future.join());
}

@Test
public void listAcl() {
CompletableFuture<List<Acl>> future = this.authorizationDisabledMetadataProvider.listAcl(null, null);
Assert.assertTrue(future.isDone());
Assert.assertNull(future.join());
}
}
Loading