提交 7a030209 编写于 作者: H hujie

accomplish

上级 9e0021db
<?xml version="1.0"?> <?xml version="1.0"?>
<project <project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<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-plug</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>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>${project.groupId}</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>rocketmq-logging</artifactId>
<version>1.19</version> </dependency>
</dependency> <dependency>
<dependency> <groupId>${project.groupId}</groupId>
<groupId>org.apache.commons</groupId> <artifactId>rocketmq-common</artifactId>
<artifactId>commons-lang3</artifactId> </dependency>
</dependency> <dependency>
</dependencies> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project> </project>
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -11,40 +27,40 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -11,40 +27,40 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class AccessContralAnalysis { public class AccessContralAnalysis {
private Map<Class<?>, Map<Integer, Field>> classTocodeAndMentod = new HashMap<>(); private Map<Class<?>, Map<Integer, Field>> classTocodeAndMentod = new HashMap<>();
public Map<Integer , Boolean> analysis(AccessControl accessControl) { public Map<Integer, Boolean> analysis(AccessControl accessControl) {
Class<? extends AccessControl> clazz = accessControl.getClass(); Class<? extends AccessControl> clazz = accessControl.getClass();
Map<Integer, Field> codeAndField = classTocodeAndMentod.get(clazz); Map<Integer, Field> codeAndField = classTocodeAndMentod.get(clazz);
if (codeAndField == null) { if (codeAndField == null) {
codeAndField = new HashMap<>(); codeAndField = new HashMap<>();
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) { for (Field field : fields) {
RequestCode requestCode = field.getAnnotation(RequestCode.class); RequestCode requestCode = field.getAnnotation(RequestCode.class);
if (requestCode != null) { if (requestCode != null) {
int code = requestCode.code(); int code = requestCode.code();
if (codeAndField.containsKey(code)) { if (codeAndField.containsKey(code)) {
} else { } else {
field.setAccessible(true); field.setAccessible(true);
codeAndField.put(code, field); codeAndField.put(code, field);
} }
} }
} }
classTocodeAndMentod.put(clazz, codeAndField); classTocodeAndMentod.put(clazz, codeAndField);
} }
Iterator<Entry<Integer, Field>> it = codeAndField.entrySet().iterator(); Iterator<Entry<Integer, Field>> it = codeAndField.entrySet().iterator();
Map<Integer, Boolean> authority = new HashMap<>(); Map<Integer, Boolean> authority = new HashMap<>();
try { try {
while (it.hasNext()) { while (it.hasNext()) {
Entry<Integer, Field> e = it.next(); Entry<Integer, Field> e = it.next();
authority.put(e.getKey(), (Boolean)e.getValue().get(accessControl)); authority.put(e.getKey(), (Boolean) e.getValue().get(accessControl));
} }
} catch (IllegalArgumentException | IllegalAccessException e1) { } catch (IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
return authority; return authority;
} }
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine; import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine; import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity; import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.exception.AclPlugStartException;
public class AclPlugController { public class AclPlugController {
private ControllerParametersEntity controllerParametersEntity;
private ControllerParametersEntity controllerParametersEntity;
private AclPlugEngine aclPlugEngine;
private AclPlugEngine aclPlugEngine;
private AclRemotingServer aclRemotingServer;
private AclRemotingServer aclRemotingServer;
private boolean startSucceed = false;
public AclPlugController(ControllerParametersEntity controllerParametersEntity){
this.controllerParametersEntity = controllerParametersEntity; public AclPlugController(ControllerParametersEntity controllerParametersEntity) throws AclPlugStartException {
aclPlugEngine = new PlainAclPlugEngine(); try {
aclRemotingServer = new DefaultAclRemotingServerImpl(aclPlugEngine); this.controllerParametersEntity = controllerParametersEntity;
} aclPlugEngine = new PlainAclPlugEngine(controllerParametersEntity);
aclRemotingServer = new DefaultAclRemotingServerImpl(aclPlugEngine);
public AclRemotingServer getAclRemotingServer() { this.startSucceed = true;
return this.aclRemotingServer; } catch (Exception e) {
} throw new AclPlugStartException(String.format("Start the abnormal , Launch parameters is %s", this.controllerParametersEntity.toString()), e);
}
}
public boolean isStartSucceed() {
return true; public AclRemotingServer getAclRemotingServer() {
} return this.aclRemotingServer;
}
public void doChannelCloseEvent(String remoteAddr) {
aclPlugEngine.deleteLoginInfo(remoteAddr);
}
public boolean isStartSucceed() {
return startSucceed;
}
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
public class AclPlugServer { public class AclPlugServer {
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
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.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclRemotingServer { public interface AclRemotingServer {
public AuthenticationInfo login();
public AuthenticationInfo login();
public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl);
public AuthenticationInfo eachCheck(LoginOrRequestAccessControl accessControl);
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class AclUtils { public class AclUtils {
public static String[] getAddreeStrArray(String netaddress, String four) {
public static String[] getAddreeStrArray(String netaddress ,String four ) { String[] fourStrArray = StringUtils.split(four.substring(1, four.length() - 1), ",");
String[] fourStrArray = StringUtils.split(four.substring(1, four.length()-1) , ","); String address = netaddress.substring(0, netaddress.indexOf("{"));
String address = netaddress.substring(0, netaddress.indexOf("{") ); String[] addreeStrArray = new String[fourStrArray.length];
String[] addreeStrArray = new String[ fourStrArray.length ]; for (int i = 0; i < fourStrArray.length; i++) {
for(int i = 0 ; i < fourStrArray.length ; i++) { addreeStrArray[i] = address + fourStrArray[i];
addreeStrArray[i] = address+fourStrArray[i]; }
} return addreeStrArray;
return addreeStrArray; }
}
public static boolean isScope(String num, int index) {
public static boolean isScope(String num, int index) { String[] strArray = StringUtils.split(num, ".");
String[] strArray = StringUtils.split(num , "."); if (strArray.length != 4) {
if(strArray.length != 4) { return false;
return false; }
} return isScope(strArray, index);
return isScope(strArray, index);
}
}
public static boolean isScope(String[] num, int index) {
public static boolean isScope(String[] num, int index) { if (num.length <= index) {
if (num.length <= index) {
}
} for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++) { if (!isScope(num[i])) {
if( !isScope(num[i])) { return false;
return false; }
} }
} return true;
return true;
}
}
public static boolean isScope(String num) {
public static boolean isScope(String num) { return isScope(Integer.valueOf(num.trim()));
return isScope(Integer.valueOf(num.trim())); }
}
public static boolean isScope(int num) {
public static boolean isScope(int num) { return num >= 0 && num <= 255;
return num >= 0 && num <= 255; }
}
public static boolean isAsterisk(String asterisk) {
public static boolean isAsterisk(String asterisk) { return asterisk.indexOf('*') > -1;
return asterisk.indexOf('*') > -1; }
}
public static boolean isColon(String colon) {
public static boolean isColon(String colon) { return colon.indexOf(',') > -1;
return colon.indexOf(',') > -1; }
}
public static boolean isMinus(String minus) {
public static boolean isMinus(String minus) { return minus.indexOf('-') > -1;
return minus.indexOf('-') > -1;
}
}
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -8,36 +24,38 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; ...@@ -8,36 +24,38 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public class Authentication { public class Authentication {
public boolean authentication(AuthenticationInfo authenticationInfo, LoginOrRequestAccessControl loginOrRequestAccessControl,AuthenticationResult authenticationResult) { public boolean authentication(AuthenticationInfo authenticationInfo,
int code = loginOrRequestAccessControl.getCode(); LoginOrRequestAccessControl loginOrRequestAccessControl, AuthenticationResult authenticationResult) {
if (authenticationInfo.getAuthority().get(code)) { int code = loginOrRequestAccessControl.getCode();
AccessControl accessControl = authenticationInfo.getAccessControl(); if (!authenticationInfo.getAuthority().get(code)) {
if( !(accessControl instanceof BorkerAccessControl)) { authenticationResult.setResultString(String.format("code is %d Authentication failed", code));
return true; return false;
} }
BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl(); AccessControl accessControl = authenticationInfo.getAccessControl();
String topicName = loginOrRequestAccessControl.getTopic(); if (!(accessControl instanceof BorkerAccessControl)) {
if (code == 10 || code == 310 || code == 320) { return true;
if (borker.getPermitSendTopic().contains(topicName)) { }
return true; BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl();
} String topicName = loginOrRequestAccessControl.getTopic();
if (borker.getNoPermitSendTopic().contains(topicName)) { if (code == 10 || code == 310 || code == 320) {
authenticationResult.setResultString(String.format("noPermitSendTopic include %s", topicName)); if (borker.getPermitSendTopic().contains(topicName)) {
return false; return true;
} }
return true; if (borker.getNoPermitSendTopic().contains(topicName)) {
} else if (code == 11) { authenticationResult.setResultString(String.format("noPermitSendTopic include %s", topicName));
if (borker.getPermitPullTopic().contains(topicName)) { return false;
return true; }
} return true;
if (borker.getNoPermitPullTopic().contains(topicName)) { } else if (code == 11) {
authenticationResult.setResultString(String.format("noPermitPullTopic include %s", topicName)); if (borker.getPermitPullTopic().contains(topicName)) {
return false; return true;
} }
return true; if (borker.getNoPermitPullTopic().contains(topicName)) {
} authenticationResult.setResultString(String.format("noPermitPullTopic include %s", topicName));
return true; return false;
} }
return false; return true;
} }
return true;
}
} }
/*
* 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.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine; import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
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.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAuthenticationException;
import org.apache.rocketmq.acl.plug.exception.AclPlugLoginException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class DefaultAclRemotingServerImpl implements AclRemotingServer { public class DefaultAclRemotingServerImpl implements AclRemotingServer {
private AclPlugEngine aclPlugEngine; private AclPlugEngine aclPlugEngine;
public DefaultAclRemotingServerImpl(AclPlugEngine aclPlugEngine ) { public DefaultAclRemotingServerImpl(AclPlugEngine aclPlugEngine) {
this.aclPlugEngine = aclPlugEngine; this.aclPlugEngine = aclPlugEngine;
} }
@Override @Override
public AuthenticationInfo login() { public AuthenticationInfo login() {
return null; return null;
} }
@Override @Override
public AuthenticationInfo eachCheck(LoginOrRequestAccessControl accessControl) { public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl) {
aclPlugEngine.eachCheckLoginAndAuthentication(accessControl); AuthenticationResult authenticationResult = aclPlugEngine.eachCheckLoginAndAuthentication(accessControl);
return null; if (authenticationResult.getException() != null) {
} throw new AclPlugRuntimeException(String.format("eachCheck the inspection appear exception, accessControl data is %s", accessControl.toString()), authenticationResult.getException());
}
if (authenticationResult.getAccessControl() == null) {
throw new AclPlugLoginException(String.format("%s accessControl data is %s", authenticationResult.getResultString(), accessControl.toString()));
}
if (!authenticationResult.isSucceed()) {
throw new AclPlugAuthenticationException(String.format("%s accessControl data is %s", authenticationResult.getResultString(), accessControl.toString()));
}
return authenticationResult;
}
} }
package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
public class EmptyImplementationAclRemotingServer implements AclRemotingServer {
@Override
public AuthenticationInfo login() {
return null;
}
@Override
public AuthenticationInfo eachCheck() {
// TODO Auto-generated method stub
return null;
}
}
/*
* 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.acl.plug.annotation; package org.apache.rocketmq.acl.plug.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
...@@ -11,5 +27,5 @@ import java.lang.annotation.Target; ...@@ -11,5 +27,5 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD}) @Target({ElementType.FIELD})
public @interface RequestCode { public @interface RequestCode {
int code(); int code();
} }
/*
* 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.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -8,9 +24,11 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; ...@@ -8,9 +24,11 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclPlugEngine { public interface AclPlugEngine {
public AuthenticationInfo getAccessControl(AccessControl accessControl) ; public AuthenticationInfo getAccessControl(AccessControl accessControl);
public LoginInfo getLoginInfo(AccessControl accessControl) ; public LoginInfo getLoginInfo(AccessControl accessControl);
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl); public void deleteLoginInfo(String remoteAddr);
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl);
} }
/*
* 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.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.util.HashMap; import java.util.HashMap;
...@@ -10,76 +26,93 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -10,76 +26,93 @@ 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;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory;
import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.InternalLogger;
import org.apache.rocketmq.logging.InternalLoggerFactory;
public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPlugEngine { public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPlugEngine {
private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.ACL_PLUG_LOGGER_NAME);
private Map<String/**account **/ , Map<String/**netaddress**/ , AuthenticationInfo>> accessControlMap = new HashMap<>();
private Map<String/** account **/, Map<String/** netaddress **/, AuthenticationInfo>> accessControlMap = new HashMap<>();
private AuthenticationInfo authenticationInfo;
private AuthenticationInfo authenticationInfo;
private NetaddressStrategyFactory netaddressStrategyFactory = new NetaddressStrategyFactory();
private NetaddressStrategyFactory netaddressStrategyFactory = new NetaddressStrategyFactory();
private AccessContralAnalysis accessContralAnalysis = new AccessContralAnalysis();
private AccessContralAnalysis accessContralAnalysis = new AccessContralAnalysis();
private Authentication authentication = new Authentication();
private Authentication authentication = new Authentication();
public void setAccessControl(AccessControl accessControl) {
try { public void setAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl); try {
Map<String , AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount()); NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
if(accessControlAddressMap == null ) { Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount());
accessControlAddressMap = new HashMap<>(); if (accessControlAddressMap == null) {
accessControlMap.put(accessControl.getAccount(), accessControlAddressMap); accessControlAddressMap = new HashMap<>();
} accessControlMap.put(accessControl.getAccount(), accessControlAddressMap);
accessControlAddressMap.put(accessControl.getNetaddress(), new AuthenticationInfo(accessContralAnalysis.analysis(accessControl),accessControl ,netaddressStrategy)); }
}catch(Exception e) { AuthenticationInfo authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategy);
// TODO Exception accessControlAddressMap.put(accessControl.getNetaddress(), authenticationInfo);
} log.info("authenticationInfo is {}", authenticationInfo.toString());
} } catch (Exception e) {
throw new AclPlugAccountAnalysisException(accessControl.toString(), e);
public void setAccessControlList(List<AccessControl> AccessControlList) { }
for(AccessControl accessControl : AccessControlList) { }
setAccessControl(accessControl);
} public void setAccessControlList(List<AccessControl> accessControlList) throws AclPlugAccountAnalysisException {
} for (AccessControl accessControl : accessControlList) {
setAccessControl(accessControl);
}
public void setNetaddressAccessControl(AccessControl accessControl) { }
authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl) , accessControl, netaddressStrategyFactory.getNetaddressStrategy(accessControl));
} public void setNetaddressAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
try {
public AuthenticationInfo getAccessControl(AccessControl accessControl) { authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategyFactory.getNetaddressStrategy(accessControl));
AuthenticationInfo existing = null; log.info("default authenticationInfo is {}", authenticationInfo.toString());
if( accessControl.getAccount() == null && authenticationInfo != null) { } catch (Exception e) {
existing = authenticationInfo.getNetaddressStrategy().match(accessControl)?authenticationInfo:null; throw new AclPlugAccountAnalysisException(accessControl.toString(), e);
}else { }
Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount());
if(accessControlAddressMap != null ) { }
existing = accessControlAddressMap.get(accessControl.getNetaddress());
if(existing.getAccessControl().getPassword().equals(accessControl.getPassword())) { public AuthenticationInfo getAccessControl(AccessControl accessControl) {
if( existing.getNetaddressStrategy().match(accessControl)) { AuthenticationInfo existing = null;
return existing; if (accessControl.getAccount() == null && authenticationInfo != null) {
} existing = authenticationInfo.getNetaddressStrategy().match(accessControl) ? authenticationInfo : null;
} } else {
existing = null; Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount());
} if (accessControlAddressMap != null) {
} existing = accessControlAddressMap.get(accessControl.getNetaddress());
return existing; if (existing.getAccessControl().getPassword().equals(accessControl.getPassword())) {
} if (existing.getNetaddressStrategy().match(accessControl)) {
return existing;
@Override }
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl) { }
AuthenticationResult authenticationResult = new AuthenticationResult(); existing = null;
AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl , authenticationResult); }
if(authenticationInfo != null) { }
boolean boo = authentication.authentication(authenticationInfo, accessControl,authenticationResult); return existing;
authenticationResult.setSucceed( boo ); }
}
return authenticationResult; @Override
} public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl) {
AuthenticationResult authenticationResult = new AuthenticationResult();
protected abstract AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl , AuthenticationResult authenticationResult); try {
AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl, authenticationResult);
if (authenticationInfo != null) {
boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
authenticationResult.setSucceed(boo);
}
} catch (Exception e) {
authenticationResult.setException(e);
}
return authenticationResult;
}
protected abstract AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
AuthenticationResult authenticationResult);
} }
/*
* 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.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.util.Map; import java.util.Map;
...@@ -11,37 +27,43 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; ...@@ -11,37 +27,43 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagementAclPlugEngine { public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagementAclPlugEngine {
private Map<String, LoginInfo> loginInfoMap = new ConcurrentHashMap<>(); private Map<String, LoginInfo> loginInfoMap = new ConcurrentHashMap<>();
@Override @Override
public AuthenticationInfo getAccessControl(AccessControl accessControl) { public AuthenticationInfo getAccessControl(AccessControl accessControl) {
AuthenticationInfo authenticationInfo = super.getAccessControl(accessControl); AuthenticationInfo authenticationInfo = super.getAccessControl(accessControl);
LoginInfo loginInfo = new LoginInfo(); if (authenticationInfo != null) {
loginInfo.setAuthenticationInfo(authenticationInfo); LoginInfo loginInfo = new LoginInfo();
loginInfoMap.put(accessControl.getRecognition(), loginInfo); loginInfo.setAuthenticationInfo(authenticationInfo);
return authenticationInfo; loginInfoMap.put(accessControl.getRecognition(), loginInfo);
} }
return authenticationInfo;
public LoginInfo getLoginInfo(AccessControl accessControl) { }
LoginInfo loginInfo = loginInfoMap.get(accessControl.getRecognition());
if (loginInfo == null) { public LoginInfo getLoginInfo(AccessControl accessControl) {
getAccessControl(accessControl); LoginInfo loginInfo = loginInfoMap.get(accessControl.getRecognition());
loginInfo = loginInfoMap.get(accessControl.getRecognition()); if (loginInfo == null && getAccessControl(accessControl) != null) {
} loginInfo = loginInfoMap.get(accessControl.getRecognition());
if (loginInfo != null) { }
loginInfo.setOperationTime(System.currentTimeMillis()); if (loginInfo != null) {
} loginInfo.setOperationTime(System.currentTimeMillis());
return loginInfo; }
} return loginInfo;
}
protected AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl , AuthenticationResult authenticationResult) { public void deleteLoginInfo(String remoteAddr) {
LoginInfo anthenticationInfo = getLoginInfo(accessControl); loginInfoMap.remove(remoteAddr);
if(anthenticationInfo != null) { }
return anthenticationInfo.getAuthenticationInfo();
}else { protected AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
authenticationResult.setResultString("Login information does not exist"); AuthenticationResult authenticationResult) {
} LoginInfo anthenticationInfo = getLoginInfo(accessControl);
return null; if (anthenticationInfo != null && anthenticationInfo.getAuthenticationInfo() != null) {
} return anthenticationInfo.getAuthenticationInfo();
} else {
authenticationResult.setResultString("Login information does not exist, Please check login, password, IP");
}
return null;
}
} }
/*
* 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.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport; import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
public class PlainAclPlugEngine extends LoginInfoAclPlugEngine { public class PlainAclPlugEngine extends LoginInfoAclPlugEngine {
public PlainAclPlugEngine() { private ControllerParametersEntity controllerParametersEntity;
init();
} public PlainAclPlugEngine(
ControllerParametersEntity controllerParametersEntity) throws AclPlugAccountAnalysisException {
void init() { this.controllerParametersEntity = controllerParametersEntity;
Yaml ymal = new Yaml(); init();
BorkerAccessControlTransport transport = ymal.loadAs(PlainAclPlugEngine.class.getClassLoader().getResourceAsStream( "transport.yml"), BorkerAccessControlTransport.class); }
super.setNetaddressAccessControl(transport.getOnlyNetAddress());
for(AccessControl accessControl : transport.getList()) { void init() throws AclPlugAccountAnalysisException {
super.setAccessControl(accessControl); String filePath = controllerParametersEntity.getFileHome() + "/conf/transport.yml";
} Yaml ymal = new Yaml();
} FileInputStream fis;
try {
fis = new FileInputStream(new File(filePath));
BorkerAccessControlTransport transport = ymal.loadAs(fis, BorkerAccessControlTransport.class);
super.setNetaddressAccessControl(transport.getOnlyNetAddress());
for (AccessControl accessControl : transport.getList()) {
super.setAccessControl(accessControl);
}
} catch (FileNotFoundException e) {
throw new AclPlugAccountAnalysisException("The transport.yml file for Plain mode was not found", e);
}
}
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class AccessControl { public class AccessControl {
private String account; private String account;
private String password; private String password;
private String netaddress; private String netaddress;
private String recognition; private String recognition;
public AccessControl() { public AccessControl() {
} }
public String getAccount() {
public String getAccount() { return account;
return account; }
}
public void setAccount(String account) {
public void setAccount(String account) { this.account = account;
this.account = account; }
}
public String getPassword() {
public String getPassword() { return password;
return password; }
}
public void setPassword(String password) {
public void setPassword(String password) { this.password = password;
this.password = password; }
}
public String getNetaddress() {
public String getNetaddress() { return netaddress;
return netaddress; }
}
public void setNetaddress(String netaddress) {
public void setNetaddress(String netaddress) { this.netaddress = netaddress;
this.netaddress = netaddress; }
}
public String getRecognition() {
public String getRecognition() { return recognition;
return recognition; }
}
public void setRecognition(String recognition) {
public void setRecognition(String recognition) { this.recognition = recognition;
this.recognition = recognition; }
}
@Override
@Override public String toString() {
public String toString() { return "AccessControl [account=" + account + ", password=" + password + ", netaddress=" + netaddress
return "AccessControl [account=" + account + ", password=" + password + ", netaddress=" + netaddress + ", recognition=" + recognition + "]";
+ ", recognition=" + recognition + "]"; }
}
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
public class AuthenticationInfo { public class AuthenticationInfo {
private AccessControl accessControl; private AccessControl accessControl;
private NetaddressStrategy netaddressStrategy; private NetaddressStrategy netaddressStrategy;
private Map<Integer, Boolean> authority; private Map<Integer, Boolean> authority;
public AuthenticationInfo(Map<Integer, Boolean> authority , AccessControl accessControl, NetaddressStrategy netaddressStrategy) { public AuthenticationInfo(Map<Integer, Boolean> authority, AccessControl accessControl,
super(); NetaddressStrategy netaddressStrategy) {
this.authority = authority; super();
this.accessControl = accessControl; this.authority = authority;
this.netaddressStrategy = netaddressStrategy; this.accessControl = accessControl;
} this.netaddressStrategy = netaddressStrategy;
}
public AccessControl getAccessControl() {
return accessControl; public AccessControl getAccessControl() {
} return accessControl;
}
public void setAccessControl(AccessControl accessControl) {
this.accessControl = accessControl; public void setAccessControl(AccessControl accessControl) {
} this.accessControl = accessControl;
}
public NetaddressStrategy getNetaddressStrategy() {
return netaddressStrategy; public NetaddressStrategy getNetaddressStrategy() {
} return netaddressStrategy;
}
public void setNetaddressStrategy(NetaddressStrategy netaddressStrategy) {
this.netaddressStrategy = netaddressStrategy; public void setNetaddressStrategy(NetaddressStrategy netaddressStrategy) {
} this.netaddressStrategy = netaddressStrategy;
}
public Map<Integer, Boolean> getAuthority() {
public Map<Integer, Boolean> getAuthority() { return authority;
return authority; }
}
public void setAuthority(Map<Integer, Boolean> authority) {
public void setAuthority(Map<Integer, Boolean> authority) { this.authority = authority;
this.authority = authority; }
}
@Override
@Override public String toString() {
public String toString() { StringBuilder builder = new StringBuilder();
return "AuthenticationInfo [accessControl=" + accessControl + ", netaddressStrategy=" + netaddressStrategy builder.append("AuthenticationInfo [accessControl=").append(accessControl).append(", netaddressStrategy=")
+ ", authority=" + authority + "]"; .append(netaddressStrategy).append(", authority={");
} Iterator<Entry<Integer, Boolean>> it = authority.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, Boolean> e = it.next();
if (!e.getValue()) {
builder.append(e.getKey().toString()).append(":").append(e.getValue()).append(",");
}
}
builder.append("}]");
return builder.toString();
}
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class AuthenticationResult { public class AuthenticationResult {
private AccessControl accessControl; private AccessControl accessControl;
private boolean succeed; private boolean succeed;
private Exception exception; private Exception exception;
private String resultString; private String resultString;
public AccessControl getAccessControl() { public AccessControl getAccessControl() {
return accessControl; return accessControl;
} }
public void setAccessControl(AccessControl accessControl) { public void setAccessControl(AccessControl accessControl) {
this.accessControl = accessControl; this.accessControl = accessControl;
} }
public boolean isSucceed() { public boolean isSucceed() {
return succeed; return succeed;
} }
public void setSucceed(boolean succeed) { public void setSucceed(boolean succeed) {
this.succeed = succeed; this.succeed = succeed;
} }
public Exception getException() { public Exception getException() {
return exception; return exception;
} }
public void setException(Exception exception) { public void setException(Exception exception) {
this.exception = exception; this.exception = exception;
} }
public String getResultString() { public String getResultString() {
return resultString; return resultString;
} }
public void setResultString(String resultString) { public void setResultString(String resultString) {
this.resultString = resultString; this.resultString = resultString;
} }
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.List; import java.util.List;
public class BorkerAccessControlTransport { public class BorkerAccessControlTransport {
private BorkerAccessControl onlyNetAddress; private BorkerAccessControl onlyNetAddress;
private List<BorkerAccessControl> list;
private List<BorkerAccessControl> list;
public BorkerAccessControlTransport() { public BorkerAccessControlTransport() {
super(); super();
} }
public BorkerAccessControl getOnlyNetAddress() { public BorkerAccessControl getOnlyNetAddress() {
return onlyNetAddress; return onlyNetAddress;
} }
public void setOnlyNetAddress(BorkerAccessControl onlyNetAddress) { public void setOnlyNetAddress(BorkerAccessControl onlyNetAddress) {
this.onlyNetAddress = onlyNetAddress; this.onlyNetAddress = onlyNetAddress;
} }
public List<BorkerAccessControl> getList() { public List<BorkerAccessControl> getList() {
return list; return list;
} }
public void setList(List<BorkerAccessControl> list) { public void setList(List<BorkerAccessControl> list) {
this.list = list; this.list = list;
} }
@Override
public String toString() {
return "BorkerAccessControlTransport [onlyNetAddress=" + onlyNetAddress + ", list=" + list + "]";
}
@Override
public String toString() {
return "BorkerAccessControlTransport [onlyNetAddress=" + onlyNetAddress + ", list=" + list + "]";
}
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class ControllerParametersEntity { public class ControllerParametersEntity {
private String fileHome;
public String getFileHome() {
return fileHome;
}
public void setFileHome(String fileHome) {
this.fileHome = fileHome;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ControllerParametersEntity [fileHome=").append(fileHome).append("]");
return builder.toString();
}
} }
/*
* 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.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.concurrent.atomic.AtomicBoolean;
public class LoginInfo { public class LoginInfo {
private String recognition;
private String recognition;
private long loginTime = System.currentTimeMillis();
private long loginTime = System.currentTimeMillis();
private volatile long operationTime = loginTime;
private long operationTime = loginTime;
private volatile AtomicBoolean clear = new AtomicBoolean();
private AuthenticationInfo authenticationInfo;
private AuthenticationInfo authenticationInfo;
public AuthenticationInfo getAuthenticationInfo() {
public AuthenticationInfo getAuthenticationInfo() { return authenticationInfo;
return authenticationInfo; }
}
public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) { this.authenticationInfo = authenticationInfo;
this.authenticationInfo = authenticationInfo; }
}
public String getRecognition() {
public String getRecognition() { return recognition;
return recognition; }
}
public void setRecognition(String recognition) {
public void setRecognition(String recognition) { this.recognition = recognition;
this.recognition = recognition; }
}
public long getLoginTime() {
public long getLoginTime() { return loginTime;
return loginTime; }
}
public void setLoginTime(long loginTime) {
public void setLoginTime(long loginTime) { this.loginTime = loginTime;
this.loginTime = loginTime; }
}
public long getOperationTime() {
public long getOperationTime() { return operationTime;
return operationTime; }
}
public void setOperationTime(long operationTime) {
public void setOperationTime(long operationTime) { this.operationTime = operationTime;
this.operationTime = operationTime; }
}
public AtomicBoolean getClear() {
@Override return clear;
public String toString() { }
return "LoginInfo [recognition=" + recognition + ", loginTime=" + loginTime + ", operationTime=" + operationTime
+ ", authenticationInfo=" + authenticationInfo + "]"; public void setClear(AtomicBoolean clear) {
} this.clear = clear;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LoginInfo [recognition=").append(recognition).append(", loginTime=").append(loginTime)
.append(", operationTime=").append(operationTime).append(", clear=").append(clear)
.append(", authenticationInfo=").append(authenticationInfo).append("]");
return builder.toString();
}
} }
package org.apache.rocketmq.acl.plug.entity; /*
* Licensed to the Apache Software Foundation (ASF) under one or more
/** * contributor license agreements. See the NOTICE file distributed with
* @author Administrator * 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.acl.plug.entity;
public class LoginOrRequestAccessControl extends AccessControl { public class LoginOrRequestAccessControl extends AccessControl {
private int code;
private int code;
private String topic;
private String topic;
public int getCode() {
public int getCode() { return code;
return code; }
}
public void setCode(int code) {
public void setCode(int code) { this.code = code;
this.code = code; }
}
public String getTopic() {
public String getTopic() { return topic;
return topic; }
}
public void setTopic(String topic) {
public void setTopic(String topic) { this.topic = topic;
this.topic = topic; }
}
@Override
@Override public String toString() {
public String toString() { StringBuilder builder = new StringBuilder();
StringBuilder builder = new StringBuilder(); builder.append("LoginOrRequestAccessControl [code=").append(code).append(", topic=").append(topic).append("]");
builder.append("LoginOrRequestAccessControl [code=").append(code).append(", topic=").append(topic).append("]"); return builder.toString();
return builder.toString(); }
}
} }
/*
* 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.acl.plug.exception;
public class AclPlugAccountAnalysisException extends AclPlugRuntimeException {
private static final long serialVersionUID = -7286948517911075176L;
public AclPlugAccountAnalysisException(String message) {
super(message);
}
public AclPlugAccountAnalysisException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.exception;
public class AclPlugAuthenticationException extends AclPlugRuntimeException {
private static final long serialVersionUID = 6365666045084521516L;
public AclPlugAuthenticationException(String message) {
super(message);
}
public AclPlugAuthenticationException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.exception;
public class AclPlugException extends Exception {
private static final long serialVersionUID = 6843154847463800519L;
public AclPlugException(String message) {
super(message);
}
public AclPlugException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.exception;
public class AclPlugLoginException extends AclPlugRuntimeException {
private static final long serialVersionUID = 4593661700080106122L;
public AclPlugLoginException(String message) {
super(message);
}
public AclPlugLoginException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.exception;
public class AclPlugRuntimeException extends RuntimeException {
private static final long serialVersionUID = 6062101368637228900L;
public AclPlugRuntimeException(String message) {
super(message);
}
public AclPlugRuntimeException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.exception;
public class AclPlugStartException extends AclPlugException {
private static final long serialVersionUID = 5118936374739373693L;
public AclPlugStartException(String message) {
super(message);
}
public AclPlugStartException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.AclUtils; import org.apache.rocketmq.acl.plug.AclUtils;
public abstract class AbstractNetaddressStrategy implements NetaddressStrategy { public abstract class AbstractNetaddressStrategy implements NetaddressStrategy {
public void verify(String netaddress , int index) { public void verify(String netaddress, int index) {
AclUtils.isScope(netaddress, index); AclUtils.isScope(netaddress, index);
} }
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import java.util.HashSet; import java.util.HashSet;
...@@ -7,19 +23,18 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -7,19 +23,18 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class MultipleNetaddressStrategy extends AbstractNetaddressStrategy { public class MultipleNetaddressStrategy extends AbstractNetaddressStrategy {
private final Set<String> multipleSet = new HashSet<>(); private final Set<String> multipleSet = new HashSet<>();
public MultipleNetaddressStrategy(String[] strArray) { public MultipleNetaddressStrategy(String[] strArray) {
for(String netaddress : strArray) { for (String netaddress : strArray) {
verify(netaddress, 4); verify(netaddress, 4);
multipleSet.add(netaddress); multipleSet.add(netaddress);
} }
} }
@Override
@Override public boolean match(AccessControl accessControl) {
public boolean match(AccessControl accessControl) { return multipleSet.contains(accessControl.getNetaddress());
return multipleSet.contains(accessControl.getNetaddress()); }
}
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
public interface NetaddressStrategy { public interface NetaddressStrategy {
public boolean match(AccessControl accessControl);
public boolean match(AccessControl accessControl);
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -6,26 +22,24 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -6,26 +22,24 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class NetaddressStrategyFactory { public class NetaddressStrategyFactory {
public NetaddressStrategy getNetaddressStrategy(AccessControl accessControl) {
String netaddress = accessControl.getNetaddress();
public NetaddressStrategy getNetaddressStrategy(AccessControl accessControl ) { if (StringUtils.isBlank(netaddress) || "*".equals(netaddress)) {
String netaddress = accessControl.getNetaddress(); return NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY;
if(StringUtils.isBlank(netaddress) || "*".equals(netaddress) ) {//* }
return NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY; if (netaddress.endsWith("}")) {
} String[] strArray = StringUtils.split(netaddress);
if(netaddress.endsWith("}")) {//1.1.1.{1,2,3,4,5} String four = strArray[3];
String[] strArray = StringUtils.split(netaddress); if (!four.startsWith("{")) {
String four = strArray[3];
if(!four.startsWith("{")) { }
return new MultipleNetaddressStrategy(AclUtils.getAddreeStrArray(netaddress, four));
} } else if (AclUtils.isColon(netaddress)) {
return new MultipleNetaddressStrategy(AclUtils.getAddreeStrArray(netaddress, four)); return new MultipleNetaddressStrategy(StringUtils.split(","));
}else if(AclUtils.isColon(netaddress)) {//1.1.1.1,1.2.3.4.5 } else if (AclUtils.isAsterisk(netaddress) || AclUtils.isMinus(netaddress)) {
return new MultipleNetaddressStrategy( StringUtils.split(",")); return new RangeNetaddressStrategy(netaddress);
}else if(AclUtils.isAsterisk(netaddress) || AclUtils.isMinus(netaddress)) {//1.2.*.* , 1.1.1.1-5 ,1.1.1-5.* }
return new RangeNetaddressStrategy(netaddress); return new OneNetaddressStrategy(netaddress);
}
return new OneNetaddressStrategy(netaddress); }
}
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class NullNetaddressStrategy implements NetaddressStrategy { public class NullNetaddressStrategy implements NetaddressStrategy {
public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy(); public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy();
@Override
@Override public boolean match(AccessControl accessControl) {
public boolean match(AccessControl accessControl) { return true;
return true; }
}
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class OneNetaddressStrategy extends AbstractNetaddressStrategy { public class OneNetaddressStrategy extends AbstractNetaddressStrategy {
private String netaddress;
private String netaddress;
public OneNetaddressStrategy(String netaddress) {
public OneNetaddressStrategy(String netaddress) { this.netaddress = netaddress;
this.netaddress = netaddress; }
}
@Override
@Override public boolean match(AccessControl accessControl) {
public boolean match(AccessControl accessControl) { return netaddress.equals(accessControl.getNetaddress());
return netaddress.equals(accessControl.getNetaddress()); }
}
} }
/*
* 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.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -6,64 +22,63 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -6,64 +22,63 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class RangeNetaddressStrategy extends AbstractNetaddressStrategy { public class RangeNetaddressStrategy extends AbstractNetaddressStrategy {
private String head; private String head;
private int start; private int start;
private int end; private int end;
private int index; private int index;
public RangeNetaddressStrategy(String netaddress) { public RangeNetaddressStrategy(String netaddress) {
String[] strArray = StringUtils.split(netaddress , "."); String[] strArray = StringUtils.split(netaddress, ".");
if( analysis(strArray , 2) ||analysis(strArray , 3) ) { if (analysis(strArray, 2) || analysis(strArray, 3)) {
verify(netaddress, index); verify(netaddress, index);
StringBuffer sb = new StringBuffer().append( strArray[0].trim()).append(".").append( strArray[1].trim()).append("."); StringBuffer sb = new StringBuffer().append(strArray[0].trim()).append(".").append(strArray[1].trim()).append(".");
if(index == 3) { if (index == 3) {
sb.append( strArray[2].trim()).append("."); sb.append(strArray[2].trim()).append(".");
} }
this.head = sb.toString(); this.head = sb.toString();
} }
} }
private boolean analysis(String[] strArray , int index ) { private boolean analysis(String[] strArray, int index) {
String value = strArray[index].trim(); String value = strArray[index].trim();
this.index = index; this.index = index;
if( "*".equals( value) ){ if ("*".equals(value)) {
setValue(0, 255); setValue(0, 255);
}else if(AclUtils.isMinus( value )) { } else if (AclUtils.isMinus(value)) {
String[] valueArray = StringUtils.split( value , "-" ); String[] valueArray = StringUtils.split(value, "-");
this.start = Integer.valueOf(valueArray[0]); this.start = Integer.valueOf(valueArray[0]);
this.end = Integer.valueOf(valueArray[1]); this.end = Integer.valueOf(valueArray[1]);
if ( !(AclUtils.isScope( end ) && AclUtils.isScope( start ) && start <= end)) { if (!(AclUtils.isScope(end) && AclUtils.isScope(start) && start <= end)) {
} }
} }
return this.end > 0 ? true : false; return this.end > 0 ? true : false;
} }
private void setValue(int start, int end) {
private void setValue(int start , int end) { this.start = start;
this.start = start ; this.end = end;
this.end = end; }
}
@Override
@Override public boolean match(AccessControl accessControl) {
public boolean match(AccessControl accessControl) { String netAddress = accessControl.getNetaddress();
String netAddress = accessControl.getNetaddress(); if (netAddress.startsWith(this.head)) {
if ( netAddress.startsWith(this.head)) { String value;
String value; if (index == 3) {
if(index == 3) { value = netAddress.substring(this.head.length());
value = netAddress.substring(this.head.length()); } else {
}else { value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
value = netAddress.substring(this.head.length() , netAddress.lastIndexOf('.')); }
} Integer address = Integer.valueOf(value);
Integer address = Integer.valueOf(value); if (address >= this.start && address <= this.end) {
if( address>= this.start && address <= this.end ) { return true;
return true; }
} }
} return false;
return false; }
}
} }
...@@ -7,11 +7,11 @@ import org.junit.Test; ...@@ -7,11 +7,11 @@ import org.junit.Test;
public class AccessContralAnalysisTest { public class AccessContralAnalysisTest {
@Test @Test
public void analysisTest() { public void analysisTest() {
AccessContralAnalysis accessContralAnalysis = new AccessContralAnalysis(); AccessContralAnalysis accessContralAnalysis = new AccessContralAnalysis();
Map<Integer, Boolean> map = accessContralAnalysis.analysis(new BorkerAccessControl()); Map<Integer, Boolean> map = accessContralAnalysis.analysis(new BorkerAccessControl());
System.out.println(map); System.out.println(map);
} }
} }
...@@ -4,9 +4,9 @@ import org.junit.Test; ...@@ -4,9 +4,9 @@ import org.junit.Test;
public class PlainAclPlugEngineTest { public class PlainAclPlugEngineTest {
@Test @Test
public void testPlainAclPlugEngineInit() { public void testPlainAclPlugEngineInit() {
PlainAclPlugEngine plainAclPlugEngine = new PlainAclPlugEngine(); //PlainAclPlugEngine plainAclPlugEngine = new PlainAclPlugEngine();
plainAclPlugEngine.init(); //plainAclPlugEngine.init();
} }
} }
onlyNetAddress: onlyNetAddress:
netaddress: 10.10.103.* netaddress: 10.10.103.*
noPermitPullTopic: noPermitPullTopic:
- broker-a - broker-a
list: list:
- account: laohu - account: laohu
password: 123456 password: 123456
netaddress: 192.0.0.* netaddress: 192.0.0.*
permitSendTopic: permitSendTopic:
- test1 - test1
- test2 - test2
- account: laohu - account: laohu
password: 123456 password: 123456
netaddress: 192.0.2.1 netaddress: 192.0.2.1
permitSendTopic: permitSendTopic:
- test3 - test3
- test4 - test4
\ No newline at end of file
onlyNetAddress:
netaddress: 10.10.103.*
noPermitPullTopic:
- broker-a
list:
- account: laohu
password: 123456
netaddress: 192.0.0.*
permitSendTopic:
- test1
- test2
- account: laohu
password: 123456
netaddress: 192.0.2.1
permitSendTopic:
- test3
- test4
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册