提交 c6297003 编写于 作者: L laohu

clean

上级 74f4213b
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<artifactId>rocketmq-all</artifactId> <artifactId>rocketmq-all</artifactId>
<version>4.4.0-SNAPSHOT</version> <version>4.4.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>rocketmq-acl-plug</artifactId> <artifactId>rocketmq-acl</artifactId>
<name>rocketmq-acl-plug ${project.version}</name> <name>rocketmq-acl-plug ${project.version}</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
......
...@@ -22,14 +22,16 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; ...@@ -22,14 +22,16 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public interface AccessValidator { public interface AccessValidator {
/** /**
* Parse to get the AccessResource(user, resource, needed permission) * Parse to get the AccessResource(user, resource, needed permission)
*
* @param request * @param request
* @return * @return
*/ */
AccessResource parse(RemotingCommand request,String remoteAddr); AccessResource parse(RemotingCommand request, String remoteAddr);
/** /**
* Validate the access resource. * Validate the access resource.
*
* @param accessResource * @param accessResource
*/ */
void validate(AccessResource accessResource) ; void validate(AccessResource accessResource);
} }
...@@ -21,11 +21,13 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; ...@@ -21,11 +21,13 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public class DefaultAccessValidator implements AccessValidator { public class DefaultAccessValidator implements AccessValidator {
@Override public AccessResource parse(RemotingCommand request,String remoteAddr ) { @Override
public AccessResource parse(RemotingCommand request, String remoteAddr) {
return null; return null;
} }
@Override public void validate(AccessResource accessResource) { @Override
public void validate(AccessResource accessResource) {
} }
} }
...@@ -16,14 +16,15 @@ ...@@ -16,14 +16,15 @@
*/ */
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class AccessContralAnalysis { public class AccessContralAnalysis {
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
*/ */
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import java.util.HashMap;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.AccessResource; import org.apache.rocketmq.acl.AccessResource;
import org.apache.rocketmq.acl.AccessValidator; import org.apache.rocketmq.acl.AccessValidator;
...@@ -29,7 +27,9 @@ import org.apache.rocketmq.acl.plug.entity.ControllerParameters; ...@@ -29,7 +27,9 @@ import org.apache.rocketmq.acl.plug.entity.ControllerParameters;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public class DefaultAclRemotingServiceImpl implements AclRemotingService ,AccessValidator{ import java.util.HashMap;
public class DefaultAclRemotingServiceImpl implements AclRemotingService, AccessValidator {
private AclPlugEngine aclPlugEngine; private AclPlugEngine aclPlugEngine;
...@@ -56,7 +56,7 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access ...@@ -56,7 +56,7 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access
} }
@Override @Override
public AccessResource parse(RemotingCommand request ,String remoteAddr) { public AccessResource parse(RemotingCommand request, String remoteAddr) {
HashMap<String, String> extFields = request.getExtFields(); HashMap<String, String> extFields = request.getExtFields();
AccessControl accessControl = new AccessControl(); AccessControl accessControl = new AccessControl();
accessControl.setCode(request.getCode()); accessControl.setCode(request.getCode());
...@@ -66,13 +66,13 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access ...@@ -66,13 +66,13 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService ,Access
accessControl.setPassword(extFields.get("password")); accessControl.setPassword(extFields.get("password"));
accessControl.setNetaddress(StringUtils.split(remoteAddr, ":")[0]); accessControl.setNetaddress(StringUtils.split(remoteAddr, ":")[0]);
accessControl.setTopic(extFields.get("topic")); accessControl.setTopic(extFields.get("topic"));
} }
return accessControl; return accessControl;
} }
@Override @Override
public void validate(AccessResource accessResource) { public void validate(AccessResource accessResource) {
AuthenticationResult authenticationResult = aclPlugEngine.eachCheckAuthentication((AccessControl)accessResource); AuthenticationResult authenticationResult = aclPlugEngine.eachCheckAuthentication((AccessControl) accessResource);
if (authenticationResult.getException() != null) { if (authenticationResult.getException() != null) {
throw new AclPlugRuntimeException(String.format("eachCheck the inspection appear exception, accessControl data is %s", accessResource.toString()), authenticationResult.getException()); throw new AclPlugRuntimeException(String.format("eachCheck the inspection appear exception, accessControl data is %s", accessResource.toString()), authenticationResult.getException());
} }
......
...@@ -20,6 +20,7 @@ import java.util.ArrayList; ...@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.rocketmq.acl.plug.AccessContralAnalysis; import org.apache.rocketmq.acl.plug.AccessContralAnalysis;
import org.apache.rocketmq.acl.plug.Authentication; import org.apache.rocketmq.acl.plug.Authentication;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -61,10 +62,10 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl ...@@ -61,10 +62,10 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
accessControlMap.put(accessControl.getAccount(), accessControlAddressList); accessControlMap.put(accessControl.getAccount(), accessControlAddressList);
} }
AuthenticationInfo authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategy); AuthenticationInfo authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategy);
accessControlAddressList.add( authenticationInfo); accessControlAddressList.add(authenticationInfo);
log.info("authenticationInfo is {}", authenticationInfo.toString()); log.info("authenticationInfo is {}", authenticationInfo.toString());
} catch (Exception e) { } catch (Exception e) {
throw new AclPlugRuntimeException(String.format("Exception info %s %s" ,e.getMessage() , accessControl.toString()), e); throw new AclPlugRuntimeException(String.format("Exception info %s %s", e.getMessage(), accessControl.toString()), e);
} }
} }
...@@ -90,8 +91,8 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl ...@@ -90,8 +91,8 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
} else { } else {
List<AuthenticationInfo> accessControlAddressList = accessControlMap.get(accessControl.getAccount()); List<AuthenticationInfo> accessControlAddressList = accessControlMap.get(accessControl.getAccount());
if (accessControlAddressList != null) { if (accessControlAddressList != null) {
for(AuthenticationInfo ai : accessControlAddressList) { for (AuthenticationInfo ai : accessControlAddressList) {
if(ai.getNetaddressStrategy().match(accessControl)&&ai.getAccessControl().getPassword().equals(accessControl.getPassword())) { if (ai.getNetaddressStrategy().match(accessControl) && ai.getAccessControl().getPassword().equals(accessControl.getPassword())) {
return ai; return ai;
} }
} }
...@@ -119,10 +120,11 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl ...@@ -119,10 +120,11 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
public AuthenticationResult eachCheckAuthentication(AccessControl accessControl) { public AuthenticationResult eachCheckAuthentication(AccessControl accessControl) {
AuthenticationResult authenticationResult = new AuthenticationResult(); AuthenticationResult authenticationResult = new AuthenticationResult();
AuthenticationInfo authenticationInfo = getAccessControl(accessControl); AuthenticationInfo authenticationInfo = getAccessControl(accessControl);
if(authenticationInfo != null) { if (authenticationInfo != null) {
boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult); boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
authenticationResult.setSucceed(boo); authenticationResult.setSucceed(boo);
}else { authenticationResult.setAccessControl(authenticationInfo.getAccessControl());
} else {
authenticationResult.setResultString("accessControl is null, Please check login, password, IP\""); authenticationResult.setResultString("accessControl is null, Please check login, password, IP\"");
} }
......
...@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.plug.engine; ...@@ -18,6 +18,7 @@ package org.apache.rocketmq.acl.plug.engine;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo; import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult; import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
......
...@@ -16,14 +16,15 @@ ...@@ -16,14 +16,15 @@
*/ */
package org.apache.rocketmq.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport; import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport;
import org.apache.rocketmq.acl.plug.entity.ControllerParameters; import org.apache.rocketmq.acl.plug.entity.ControllerParameters;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class PlainAclPlugEngine extends LoginInfoAclPlugEngine { public class PlainAclPlugEngine extends LoginInfoAclPlugEngine {
public PlainAclPlugEngine( public PlainAclPlugEngine(
......
...@@ -18,7 +18,7 @@ package org.apache.rocketmq.acl.plug.entity; ...@@ -18,7 +18,7 @@ package org.apache.rocketmq.acl.plug.entity;
import org.apache.rocketmq.acl.AccessResource; import org.apache.rocketmq.acl.AccessResource;
public class AccessControl implements AccessResource{ public class AccessControl implements AccessResource {
private String account; private String account;
......
...@@ -16,10 +16,11 @@ ...@@ -16,10 +16,11 @@
*/ */
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
public class AuthenticationInfo { public class AuthenticationInfo {
......
...@@ -16,13 +16,14 @@ ...@@ -16,13 +16,14 @@
*/ */
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.AclUtils; import org.apache.rocketmq.acl.plug.AclUtils;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import java.util.HashSet;
import java.util.Set;
public class NetaddressStrategyFactory { public class NetaddressStrategyFactory {
public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy(); public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy();
......
...@@ -45,7 +45,6 @@ public class AclRemotingServiceTest { ...@@ -45,7 +45,6 @@ public class AclRemotingServiceTest {
} }
@Test @Test
public void defaultConstructorTest() { public void defaultConstructorTest() {
System.setProperty("rocketmq.home.dir", "src/test/resources"); System.setProperty("rocketmq.home.dir", "src/test/resources");
...@@ -56,14 +55,14 @@ public class AclRemotingServiceTest { ...@@ -56,14 +55,14 @@ public class AclRemotingServiceTest {
@Test @Test
public void parseTest() { public void parseTest() {
RemotingCommand remotingCommand = RemotingCommand.createResponseCommand(34, ""); RemotingCommand remotingCommand = RemotingCommand.createResponseCommand(34, "");
HashMap<String ,String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("account", "RocketMQ"); map.put("account", "RocketMQ");
map.put("password","123456"); map.put("password", "123456");
map.put("topic","test"); map.put("topic", "test");
remotingCommand.setExtFields(map); remotingCommand.setExtFields(map);
AccessResource accessResource = accessValidator.parse(remotingCommand, "127.0.0.1:123"); AccessResource accessResource = accessValidator.parse(remotingCommand, "127.0.0.1:123");
AccessControl accessControl = (AccessControl)accessResource; AccessControl accessControl = (AccessControl) accessResource;
AccessControl newAccessControl = new AccessControl(); AccessControl newAccessControl = new AccessControl();
newAccessControl.setAccount("RocketMQ"); newAccessControl.setAccount("RocketMQ");
newAccessControl.setPassword("123456"); newAccessControl.setPassword("123456");
...@@ -81,21 +80,21 @@ public class AclRemotingServiceTest { ...@@ -81,21 +80,21 @@ public class AclRemotingServiceTest {
Assert.assertTrue(authenticationResult.isSucceed()); Assert.assertTrue(authenticationResult.isSucceed());
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void checkAccessExceptionTest() { public void checkAccessExceptionTest() {
accessControl.setCode(34); accessControl.setCode(34);
accessControl.setAccount("Rocketmq"); accessControl.setAccount("Rocketmq");
defaultAclService.check(accessControl); defaultAclService.check(accessControl);
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void checkPasswordTest() { public void checkPasswordTest() {
accessControl.setCode(34); accessControl.setCode(34);
accessControl.setPassword("123123123"); accessControl.setPassword("123123123");
defaultAclService.check(accessControl); defaultAclService.check(accessControl);
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void checkCodeTest() { public void checkCodeTest() {
accessControl.setCode(14434); accessControl.setCode(14434);
accessControl.setPassword("123123123"); accessControl.setPassword("123123123");
...@@ -109,21 +108,21 @@ public class AclRemotingServiceTest { ...@@ -109,21 +108,21 @@ public class AclRemotingServiceTest {
accessValidator.validate(accessControl); accessValidator.validate(accessControl);
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void validateAccessExceptionTest() { public void validateAccessExceptionTest() {
accessControl.setCode(34); accessControl.setCode(34);
accessControl.setAccount("Rocketmq"); accessControl.setAccount("Rocketmq");
accessValidator.validate(accessControl); accessValidator.validate(accessControl);
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void validatePasswordTest() { public void validatePasswordTest() {
accessControl.setCode(34); accessControl.setCode(34);
accessControl.setPassword("123123123"); accessControl.setPassword("123123123");
accessValidator.validate(accessControl); accessValidator.validate(accessControl);
} }
@Test(expected=AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void validateCodeTest() { public void validateCodeTest() {
accessControl.setCode(14434); accessControl.setCode(14434);
accessControl.setPassword("123123123"); accessControl.setPassword("123123123");
......
...@@ -18,13 +18,12 @@ package org.apache.rocketmq.acl.plug; ...@@ -18,13 +18,12 @@ package org.apache.rocketmq.acl.plug;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class AclUtilsTest { public class AclUtilsTest {
@Test @Test
......
...@@ -57,46 +57,14 @@ public class PlainAclPlugEngineTest { ...@@ -57,46 +57,14 @@ public class PlainAclPlugEngineTest {
@Before @Before
public void init() throws NoSuchFieldException, SecurityException, IOException { public void init() throws NoSuchFieldException, SecurityException, IOException {
System.setProperty("rocketmq.home.dir", "src/test/resources");
ControllerParameters controllerParametersEntity = new ControllerParameters();
Yaml ymal = new Yaml(); Yaml ymal = new Yaml();
String home = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); transport = ymal.loadAs(new FileInputStream(new File(controllerParametersEntity.getFileHome()+"/conf/transport.yml")), BorkerAccessControlTransport.class);
InputStream fis = null;
if (home == null) {
URL url = PlainAclPlugEngineTest.class.getResource("/");
home = url.toString();
home = home.substring(0, home.length() - 1).replace("file:/", "").replace("target/test-classes", "");
home = home + "src/test/resources";
if (!new File(home + "/conf/transport.yml").exists()) {
home = "/home/travis/build/githublaohu/rocketmq/acl-plug/src/test/resources";
}
}
String filePath = home + "/conf/transport.yml";
try {
fis = new FileInputStream(new File(filePath));
transport = ymal.loadAs(fis, BorkerAccessControlTransport.class);
}catch(Exception e) {
AccessControl accessControl = new BorkerAccessControl();
accessControl.setAccount("onlyNetAddress");
accessControl.setPassword("aliyun11");
accessControl.setNetaddress("127.0.0.1");
accessControl.setRecognition("127.0.0.1:1");
AccessControl accessControlTwo = new BorkerAccessControl();
accessControlTwo.setAccount("listTransport");
accessControlTwo.setPassword("aliyun1");
accessControlTwo.setNetaddress("127.0.0.1");
accessControlTwo.setRecognition("127.0.0.1:2");
transport = new BorkerAccessControlTransport();
transport.setOnlyNetAddress((BorkerAccessControl)accessControl);
}
ControllerParameters controllerParametersEntity = new ControllerParameters();
controllerParametersEntity.setFileHome(null);
try {
plainAclPlugEngine = new PlainAclPlugEngine(controllerParametersEntity); plainAclPlugEngine = new PlainAclPlugEngine(controllerParametersEntity);
plainAclPlugEngine.initialize(); plainAclPlugEngine.initialize();
} catch (Exception e) {
}
accessControl = new BorkerAccessControl(); accessControl = new BorkerAccessControl();
accessControl.setAccount("rokcetmq"); accessControl.setAccount("rokcetmq");
...@@ -142,6 +110,7 @@ public class PlainAclPlugEngineTest { ...@@ -142,6 +110,7 @@ public class PlainAclPlugEngineTest {
@Test(expected = AclPlugRuntimeException.class) @Test(expected = AclPlugRuntimeException.class)
public void testPlainAclPlugEngineInit() { public void testPlainAclPlugEngineInit() {
ControllerParameters controllerParametersEntity = new ControllerParameters(); ControllerParameters controllerParametersEntity = new ControllerParameters();
controllerParametersEntity.setFileHome("");
new PlainAclPlugEngine(controllerParametersEntity).initialize(); new PlainAclPlugEngine(controllerParametersEntity).initialize();
} }
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>rocketmq-acl-plug</artifactId> <artifactId>rocketmq-acl</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
......
...@@ -32,7 +32,6 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -32,7 +32,6 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.acl.AccessValidator; import org.apache.rocketmq.acl.AccessValidator;
import org.apache.rocketmq.acl.plug.AclPlugController;
import org.apache.rocketmq.broker.client.ClientHousekeepingService; import org.apache.rocketmq.broker.client.ClientHousekeepingService;
import org.apache.rocketmq.broker.client.ConsumerIdsChangeListener; import org.apache.rocketmq.broker.client.ConsumerIdsChangeListener;
import org.apache.rocketmq.broker.client.ConsumerManager; import org.apache.rocketmq.broker.client.ConsumerManager;
......
...@@ -525,7 +525,7 @@ ...@@ -525,7 +525,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>rocketmq-acl-plug</artifactId> <artifactId>rocketmq-acl</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册