提交 1e3c1841 编写于 作者: H hujie

clear

上级 a1a46168
......@@ -26,6 +26,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rocketmq-remoting</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rocketmq-logging</artifactId>
......
......@@ -23,7 +23,7 @@ import java.util.Map;
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.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class AccessContralAnalysis {
......@@ -42,7 +42,7 @@ public class AccessContralAnalysis {
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new AclPlugAccountAnalysisException(String.format("analysis on failure Class is %s", clazz.getName()), e);
throw new AclPlugRuntimeException(String.format("analysis on failure Class is %s", clazz.getName()), e);
}
}
......@@ -57,14 +57,14 @@ public class AccessContralAnalysis {
continue;
Integer code = fieldNameAndCode.get(field.getName().toLowerCase());
if (code == null) {
throw new AclPlugAccountAnalysisException(String.format("field nonexistent in code fieldName is %s", field.getName()));
throw new AclPlugRuntimeException(String.format("field nonexistent in code fieldName is %s", field.getName()));
}
field.setAccessible(true);
codeAndField.put(code, field);
}
if (codeAndField.isEmpty()) {
throw new AclPlugAccountAnalysisException(String.format("AccessControl nonexistent code , name %s", accessControl.getClass().getName()));
throw new AclPlugRuntimeException(String.format("AccessControl nonexistent code , name %s", accessControl.getClass().getName()));
}
classTocodeAndMentod.put(clazz, codeAndField);
}
......@@ -76,7 +76,7 @@ public class AccessContralAnalysis {
authority.put(e.getKey(), (Boolean) e.getValue().get(accessControl));
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new AclPlugAccountAnalysisException(String.format("analysis on failure AccessControl is %s", AccessControl.class.getName()), e);
throw new AclPlugRuntimeException(String.format("analysis on failure AccessControl is %s", AccessControl.class.getName()), e);
}
return authority;
}
......
......@@ -19,7 +19,7 @@ package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.exception.AclPlugStartException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class AclPlugController {
......@@ -31,14 +31,14 @@ public class AclPlugController {
private boolean startSucceed = false;
public AclPlugController(ControllerParametersEntity controllerParametersEntity) throws AclPlugStartException {
public AclPlugController(ControllerParametersEntity controllerParametersEntity) throws AclPlugRuntimeException {
try {
this.controllerParametersEntity = controllerParametersEntity;
aclPlugEngine = new PlainAclPlugEngine(controllerParametersEntity);
aclRemotingServer = new DefaultAclRemotingServerImpl(aclPlugEngine);
this.startSucceed = true;
} catch (Exception e) {
throw new AclPlugStartException(String.format("Start the abnormal , Launch parameters is %s", this.controllerParametersEntity.toString()), e);
throw new AclPlugRuntimeException(String.format("Start the abnormal , Launch parameters is %s", this.controllerParametersEntity.toString()), 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;
public class AclPlugServer {
}
......@@ -16,11 +16,11 @@
*/
package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclRemotingServer {
public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl);
public AuthenticationResult eachCheck(AccessControl accessControl);
}
......@@ -17,9 +17,16 @@
package org.apache.rocketmq.acl.plug;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class AclUtils {
public static void verify(String netaddress, int index) {
if (!AclUtils.isScope(netaddress, index)) {
throw new AclPlugRuntimeException(String.format("netaddress examine scope Exception netaddress is %s", netaddress));
}
}
public static String[] getAddreeStrArray(String netaddress, String four) {
String[] fourStrArray = StringUtils.split(four.substring(1, four.length() - 1), ",");
String address = netaddress.substring(0, netaddress.indexOf("{"));
......
......@@ -20,23 +20,21 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public class Authentication {
public boolean authentication(AuthenticationInfo authenticationInfo,
LoginOrRequestAccessControl loginOrRequestAccessControl, AuthenticationResult authenticationResult) {
int code = loginOrRequestAccessControl.getCode();
AccessControl accessControl, AuthenticationResult authenticationResult) {
int code = accessControl.getCode();
if (!authenticationInfo.getAuthority().get(code)) {
authenticationResult.setResultString(String.format("code is %d Authentication failed", code));
return false;
}
AccessControl accessControl = authenticationInfo.getAccessControl();
if (!(accessControl instanceof BorkerAccessControl)) {
if (!(authenticationInfo.getAccessControl() instanceof BorkerAccessControl)) {
return true;
}
BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl();
String topicName = loginOrRequestAccessControl.getTopic();
String topicName = accessControl.getTopic();
if (code == 10 || code == 310 || code == 320) {
if (borker.getPermitSendTopic().contains(topicName)) {
return true;
......
......@@ -17,10 +17,8 @@
package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
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 {
......@@ -32,16 +30,16 @@ public class DefaultAclRemotingServerImpl implements AclRemotingServer {
}
@Override
public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl) {
public AuthenticationResult eachCheck(AccessControl accessControl) {
AuthenticationResult authenticationResult = aclPlugEngine.eachCheckLoginAndAuthentication(accessControl);
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()));
throw new AclPlugRuntimeException(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()));
throw new AclPlugRuntimeException(String.format("%s accessControl data is %s", authenticationResult.getResultString(), accessControl.toString()));
}
return authenticationResult;
}
......
......@@ -20,7 +20,6 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.LoginInfo;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclPlugEngine {
......@@ -30,5 +29,5 @@ public interface AclPlugEngine {
public void deleteLoginInfo(String remoteAddr);
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl);
public AuthenticationResult eachCheckLoginAndAuthentication(AccessControl accessControl);
}
......@@ -26,8 +26,7 @@ import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory;
import org.apache.rocketmq.common.constant.LoggerName;
......@@ -49,9 +48,9 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
accessContralAnalysis.analysisClass(controllerParametersEntity.getAccessContralAnalysisClass());
}
public void setAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
public void setAccessControl(AccessControl accessControl) throws AclPlugRuntimeException {
if (accessControl.getAccount() == null || accessControl.getPassword() == null || accessControl.getAccount().length() <= 6 || accessControl.getPassword().length() <= 6) {
throw new AclPlugAccountAnalysisException(String.format("The account password cannot be null and is longer than 6, account is %s password is %s", accessControl.getAccount(), accessControl.getPassword()));
throw new AclPlugRuntimeException(String.format("The account password cannot be null and is longer than 6, account is %s password is %s", accessControl.getAccount(), accessControl.getPassword()));
}
try {
NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
......@@ -64,22 +63,22 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
accessControlAddressMap.put(accessControl.getNetaddress(), authenticationInfo);
log.info("authenticationInfo is {}", authenticationInfo.toString());
} catch (Exception e) {
throw new AclPlugAccountAnalysisException(accessControl.toString(), e);
throw new AclPlugRuntimeException(accessControl.toString(), e);
}
}
public void setAccessControlList(List<AccessControl> accessControlList) throws AclPlugAccountAnalysisException {
public void setAccessControlList(List<AccessControl> accessControlList) throws AclPlugRuntimeException {
for (AccessControl accessControl : accessControlList) {
setAccessControl(accessControl);
}
}
public void setNetaddressAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
public void setNetaddressAccessControl(AccessControl accessControl) throws AclPlugRuntimeException {
try {
authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategyFactory.getNetaddressStrategy(accessControl));
log.info("default authenticationInfo is {}", authenticationInfo.toString());
} catch (Exception e) {
throw new AclPlugAccountAnalysisException(accessControl.toString(), e);
throw new AclPlugRuntimeException(accessControl.toString(), e);
}
}
......@@ -106,7 +105,7 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
}
@Override
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl) {
public AuthenticationResult eachCheckLoginAndAuthentication(AccessControl accessControl) {
AuthenticationResult authenticationResult = new AuthenticationResult();
try {
AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl, authenticationResult);
......@@ -122,7 +121,7 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
void setBorkerAccessControlTransport(BorkerAccessControlTransport transport) {
if (transport.getOnlyNetAddress() == null && (transport.getList() == null || transport.getList().size() == 0)) {
throw new AclPlugAccountAnalysisException("onlyNetAddress and list can't be all empty");
throw new AclPlugRuntimeException("onlyNetAddress and list can't be all empty");
}
if (transport.getOnlyNetAddress() != null) {
......@@ -135,6 +134,6 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
}
}
protected abstract AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
protected abstract AuthenticationInfo getAuthenticationInfo(AccessControl accessControl,
AuthenticationResult authenticationResult);
}
......@@ -23,7 +23,6 @@ import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.entity.LoginInfo;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagementAclPlugEngine {
......@@ -53,7 +52,7 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen
loginInfoMap.remove(remoteAddr);
}
protected AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
protected AuthenticationInfo getAuthenticationInfo(AccessControl accessControl,
AuthenticationResult authenticationResult) {
LoginInfo loginInfo = getLoginInfo(accessControl);
if (loginInfo != null && loginInfo.getAuthenticationInfo() != null) {
......
......@@ -21,18 +21,18 @@ import java.io.FileInputStream;
import java.io.IOException;
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.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.yaml.snakeyaml.Yaml;
public class PlainAclPlugEngine extends LoginInfoAclPlugEngine {
public PlainAclPlugEngine(
ControllerParametersEntity controllerParametersEntity) throws AclPlugAccountAnalysisException {
ControllerParametersEntity controllerParametersEntity) throws AclPlugRuntimeException {
super(controllerParametersEntity);
init();
}
void init() throws AclPlugAccountAnalysisException {
void init() throws AclPlugRuntimeException {
String filePath = controllerParametersEntity.getFileHome() + "/conf/transport.yml";
Yaml ymal = new Yaml();
FileInputStream fis = null;
......@@ -41,18 +41,18 @@ public class PlainAclPlugEngine extends LoginInfoAclPlugEngine {
fis = new FileInputStream(new File(filePath));
transport = ymal.loadAs(fis, BorkerAccessControlTransport.class);
} catch (Exception e) {
throw new AclPlugAccountAnalysisException("The transport.yml file for Plain mode was not found", e);
throw new AclPlugRuntimeException("The transport.yml file for Plain mode was not found", e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
throw new AclPlugAccountAnalysisException("close transport fileInputStream Exception", e);
throw new AclPlugRuntimeException("close transport fileInputStream Exception", e);
}
}
}
if (transport == null) {
throw new AclPlugAccountAnalysisException("transport.yml file is no data");
throw new AclPlugRuntimeException("transport.yml file is no data");
}
super.setBorkerAccessControlTransport(transport);
}
......
......@@ -26,6 +26,10 @@ public class AccessControl {
private String recognition;
private int code;
private String topic;
public AccessControl() {
}
......@@ -61,10 +65,29 @@ public class AccessControl {
this.recognition = recognition;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
@Override
public String toString() {
return "AccessControl [account=" + account + ", password=" + password + ", netaddress=" + netaddress
+ ", recognition=" + recognition + "]";
StringBuilder builder = new StringBuilder();
builder.append("AccessControl [account=").append(account).append(", password=").append(password)
.append(", netaddress=").append(netaddress).append(", recognition=").append(recognition)
.append(", code=").append(code).append(", topic=").append(topic).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;
public class LoginOrRequestAccessControl extends AccessControl {
private int code;
private String topic;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LoginOrRequestAccessControl [code=").append(code).append(", topic=").append(topic).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.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 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;
import org.apache.rocketmq.acl.plug.AclUtils;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
public abstract class AbstractNetaddressStrategy implements NetaddressStrategy {
public void verify(String netaddress, int index) {
if (!AclUtils.isScope(netaddress, index)) {
throw new AclPlugAccountAnalysisException(String.format("netaddress examine scope Exception netaddress is %s", 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;
import java.util.HashSet;
import java.util.Set;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class MultipleNetaddressStrategy extends AbstractNetaddressStrategy {
private final Set<String> multipleSet = new HashSet<>();
public MultipleNetaddressStrategy(String[] strArray) {
for (String netaddress : strArray) {
verify(netaddress, 4);
multipleSet.add(netaddress);
}
}
@Override
public boolean match(AccessControl accessControl) {
return multipleSet.contains(accessControl.getNetaddress());
}
}
......@@ -16,23 +16,27 @@
*/
package org.apache.rocketmq.acl.plug.strategy;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.AclUtils;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class NetaddressStrategyFactory {
public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy();
public NetaddressStrategy getNetaddressStrategy(AccessControl accessControl) {
String netaddress = accessControl.getNetaddress();
if (StringUtils.isBlank(netaddress) || "*".equals(netaddress)) {
return NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY;
return NULL_NET_ADDRESS_STRATEGY;
}
if (netaddress.endsWith("}")) {
String[] strArray = StringUtils.split(netaddress, ".");
String four = strArray[3];
if (!four.startsWith("{")) {
throw new AclPlugAccountAnalysisException(String.format("MultipleNetaddressStrategy netaddress examine scope Exception netaddress", netaddress));
throw new AclPlugRuntimeException(String.format("MultipleNetaddressStrategy netaddress examine scope Exception netaddress", netaddress));
}
return new MultipleNetaddressStrategy(AclUtils.getAddreeStrArray(netaddress, four));
} else if (AclUtils.isColon(netaddress)) {
......@@ -43,4 +47,114 @@ public class NetaddressStrategyFactory {
return new OneNetaddressStrategy(netaddress);
}
public static class NullNetaddressStrategy implements NetaddressStrategy {
@Override
public boolean match(AccessControl accessControl) {
return true;
}
}
public static class MultipleNetaddressStrategy implements NetaddressStrategy {
private final Set<String> multipleSet = new HashSet<>();
public MultipleNetaddressStrategy(String[] strArray) {
for (String netaddress : strArray) {
AclUtils.verify(netaddress, 4);
multipleSet.add(netaddress);
}
}
@Override
public boolean match(AccessControl accessControl) {
return multipleSet.contains(accessControl.getNetaddress());
}
}
public static class OneNetaddressStrategy implements NetaddressStrategy {
private String netaddress;
public OneNetaddressStrategy(String netaddress) {
this.netaddress = netaddress;
AclUtils.verify(netaddress, 4);
}
@Override
public boolean match(AccessControl accessControl) {
return netaddress.equals(accessControl.getNetaddress());
}
}
public static class RangeNetaddressStrategy implements NetaddressStrategy {
private String head;
private int start;
private int end;
private int index;
public RangeNetaddressStrategy(String netaddress) {
String[] strArray = StringUtils.split(netaddress, ".");
if (analysis(strArray, 2) || analysis(strArray, 3)) {
AclUtils.verify(netaddress, index - 1);
StringBuffer sb = new StringBuffer().append(strArray[0].trim()).append(".").append(strArray[1].trim()).append(".");
if (index == 3) {
sb.append(strArray[2].trim()).append(".");
}
this.head = sb.toString();
}
}
private boolean analysis(String[] strArray, int index) {
String value = strArray[index].trim();
this.index = index;
if ("*".equals(value)) {
setValue(0, 255);
} else if (AclUtils.isMinus(value)) {
if (value.indexOf("-") == 0) {
throw new AclPlugRuntimeException(String.format("RangeNetaddressStrategy netaddress examine scope Exception value %s ", value));
}
String[] valueArray = StringUtils.split(value, "-");
this.start = Integer.valueOf(valueArray[0]);
this.end = Integer.valueOf(valueArray[1]);
if (!(AclUtils.isScope(end) && AclUtils.isScope(start) && start <= end)) {
throw new AclPlugRuntimeException(String.format("RangeNetaddressStrategy netaddress examine scope Exception start is %s , end is %s", start, end));
}
}
return this.end > 0 ? true : false;
}
private void setValue(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public boolean match(AccessControl accessControl) {
String netAddress = accessControl.getNetaddress();
if (netAddress.startsWith(this.head)) {
String value;
if (index == 3) {
value = netAddress.substring(this.head.length());
} else {
value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
}
Integer address = Integer.valueOf(value);
if (address >= this.start && address <= this.end) {
return true;
}
}
return false;
}
}
}
/*
* 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;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class NullNetaddressStrategy implements NetaddressStrategy {
public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy();
@Override
public boolean match(AccessControl accessControl) {
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;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class OneNetaddressStrategy extends AbstractNetaddressStrategy {
private String netaddress;
public OneNetaddressStrategy(String netaddress) {
this.netaddress = netaddress;
verify(netaddress, 4);
}
@Override
public boolean match(AccessControl accessControl) {
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;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.AclUtils;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
public class RangeNetaddressStrategy extends AbstractNetaddressStrategy {
private String head;
private int start;
private int end;
private int index;
public RangeNetaddressStrategy(String netaddress) {
String[] strArray = StringUtils.split(netaddress, ".");
if (analysis(strArray, 2) || analysis(strArray, 3)) {
verify(netaddress, index - 1);
StringBuffer sb = new StringBuffer().append(strArray[0].trim()).append(".").append(strArray[1].trim()).append(".");
if (index == 3) {
sb.append(strArray[2].trim()).append(".");
}
this.head = sb.toString();
}
}
private boolean analysis(String[] strArray, int index) {
String value = strArray[index].trim();
this.index = index;
if ("*".equals(value)) {
setValue(0, 255);
} else if (AclUtils.isMinus(value)) {
if (value.indexOf("-") == 0) {
throw new AclPlugAccountAnalysisException(String.format("RangeNetaddressStrategy netaddress examine scope Exception value %s ", value));
}
String[] valueArray = StringUtils.split(value, "-");
this.start = Integer.valueOf(valueArray[0]);
this.end = Integer.valueOf(valueArray[1]);
if (!(AclUtils.isScope(end) && AclUtils.isScope(start) && start <= end)) {
throw new AclPlugAccountAnalysisException(String.format("RangeNetaddressStrategy netaddress examine scope Exception start is %s , end is %s", start, end));
}
}
return this.end > 0 ? true : false;
}
private void setValue(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public boolean match(AccessControl accessControl) {
String netAddress = accessControl.getNetaddress();
if (netAddress.startsWith(this.head)) {
String value;
if (index == 3) {
value = netAddress.substring(this.head.length());
} else {
value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
}
Integer address = Integer.valueOf(value);
if (address >= this.start && address <= this.end) {
return true;
}
}
return false;
}
}
......@@ -21,7 +21,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.apache.rocketmq.common.protocol.RequestCode;
import org.junit.Assert;
import org.junit.Before;
......@@ -54,7 +54,7 @@ public class AccessContralAnalysisTest {
Assert.assertEquals(num, 1);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void analysisExceptionTest() {
AccessControl accessControl = new AccessControl();
accessContralAnalysis.analysis(accessControl);
......
......@@ -19,11 +19,11 @@ package org.apache.rocketmq.acl.plug;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.strategy.OneNetaddressStrategy;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory;
import org.apache.rocketmq.common.protocol.RequestCode;
import org.junit.Assert;
import org.junit.Before;
......@@ -38,11 +38,10 @@ public class AuthenticationTest {
BorkerAccessControl borkerAccessControl;
AuthenticationResult authenticationResult = new AuthenticationResult();
LoginOrRequestAccessControl loginOrRequestAccessControl = new LoginOrRequestAccessControl();
AccessControl accessControl = new AccessControl();
@Before
public void init() {
OneNetaddressStrategy netaddressStrategy = new OneNetaddressStrategy("127.0.0.1");
borkerAccessControl = new BorkerAccessControl();
//321
borkerAccessControl.setQueryConsumeQueue(false);
......@@ -67,75 +66,75 @@ public class AuthenticationTest {
accessContralAnalysis.analysisClass(RequestCode.class);
Map<Integer, Boolean> map = accessContralAnalysis.analysis(borkerAccessControl);
authenticationInfo = new AuthenticationInfo(map, borkerAccessControl, netaddressStrategy);
authenticationInfo = new AuthenticationInfo(map, borkerAccessControl, NetaddressStrategyFactory.NULL_NET_ADDRESS_STRATEGY);
}
@Test
public void authenticationTest() {
loginOrRequestAccessControl.setCode(317);
accessControl.setCode(317);
boolean isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
boolean isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setCode(321);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(321);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
loginOrRequestAccessControl.setCode(10);
loginOrRequestAccessControl.setTopic("permitSendTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(10);
accessControl.setTopic("permitSendTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setCode(310);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(310);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setCode(320);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(320);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setTopic("noPermitSendTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setTopic("noPermitSendTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
loginOrRequestAccessControl.setTopic("nopermitSendTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setTopic("nopermitSendTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
loginOrRequestAccessControl.setCode(11);
loginOrRequestAccessControl.setTopic("permitPullTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(11);
accessControl.setTopic("permitPullTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setTopic("noPermitPullTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setTopic("noPermitPullTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
loginOrRequestAccessControl.setTopic("nopermitPullTopic");
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setTopic("nopermitPullTopic");
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
}
@Test
public void isEmptyTest() {
loginOrRequestAccessControl.setCode(10);
loginOrRequestAccessControl.setTopic("absentTopic");
boolean isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(10);
accessControl.setTopic("absentTopic");
boolean isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
Set<String> permitSendTopic = new HashSet<>();
borkerAccessControl.setPermitSendTopic(permitSendTopic);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
loginOrRequestAccessControl.setCode(11);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
accessControl.setCode(11);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertFalse(isReturn);
borkerAccessControl.setPermitPullTopic(permitSendTopic);
isReturn = authentication.authentication(authenticationInfo, loginOrRequestAccessControl, authenticationResult);
isReturn = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
Assert.assertTrue(isReturn);
}
......
......@@ -30,8 +30,7 @@ import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.entity.LoginInfo;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.apache.rocketmq.common.MixAll;
import org.junit.Assert;
import org.junit.Before;
......@@ -83,31 +82,31 @@ public class PlainAclPlugEngineTest {
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void accountNullTest() {
accessControl.setAccount(null);
plainAclPlugEngine.setAccessControl(accessControl);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void accountThanTest() {
accessControl.setAccount("123");
plainAclPlugEngine.setAccessControl(accessControl);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void passWordtNullTest() {
accessControl.setAccount(null);
plainAclPlugEngine.setAccessControl(accessControl);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void passWordThanTest() {
accessControl.setAccount("123");
plainAclPlugEngine.setAccessControl(accessControl);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void testPlainAclPlugEngineInit() {
ControllerParametersEntity controllerParametersEntity = new ControllerParametersEntity();
new PlainAclPlugEngine(controllerParametersEntity);
......@@ -186,7 +185,7 @@ public class PlainAclPlugEngineTest {
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void borkerAccessControlTransportTestNull() {
plainAclPlugEngine.setBorkerAccessControlTransport(new BorkerAccessControlTransport());
}
......@@ -241,18 +240,18 @@ public class PlainAclPlugEngineTest {
@Test
public void getAuthenticationInfo() {
LoginOrRequestAccessControl loginOrRequestAccessControl = new LoginOrRequestAccessControl();
loginOrRequestAccessControl.setAccount("rokcetmq");
loginOrRequestAccessControl.setPassword("aliyun11");
loginOrRequestAccessControl.setNetaddress("127.0.0.1");
loginOrRequestAccessControl.setRecognition("127.0.0.1:1");
AccessControl AccessControl = new AccessControl();
AccessControl.setAccount("rokcetmq");
AccessControl.setPassword("aliyun11");
AccessControl.setNetaddress("127.0.0.1");
AccessControl.setRecognition("127.0.0.1:1");
AuthenticationResult authenticationResult = new AuthenticationResult();
plainAclPlugEngine.getAuthenticationInfo(loginOrRequestAccessControl, authenticationResult);
plainAclPlugEngine.getAuthenticationInfo(AccessControl, authenticationResult);
Assert.assertEquals("Login information does not exist, Please check login, password, IP", authenticationResult.getResultString());
plainAclPlugEngine.setAccessControl(accessControl);
AuthenticationInfo authenticationInfo = plainAclPlugEngine.getAuthenticationInfo(loginOrRequestAccessControl, authenticationResult);
AuthenticationInfo authenticationInfo = plainAclPlugEngine.getAuthenticationInfo(AccessControl, authenticationResult);
Assert.assertNotNull(authenticationInfo);
}
......
......@@ -17,7 +17,7 @@
package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
import org.junit.Assert;
import org.junit.Test;
......@@ -29,53 +29,57 @@ public class NetaddressStrategyTest {
public void NetaddressStrategyFactoryTest() {
AccessControl accessControl = new AccessControl();
NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy, NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY);
Assert.assertEquals(netaddressStrategy, NetaddressStrategyFactory.NULL_NET_ADDRESS_STRATEGY);
accessControl.setNetaddress("*");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy, NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY);
Assert.assertEquals(netaddressStrategy, NetaddressStrategyFactory.NULL_NET_ADDRESS_STRATEGY);
accessControl.setNetaddress("127.0.0.1");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), OneNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.OneNetaddressStrategy.class);
accessControl.setNetaddress("127.0.0.1,127.0.0.2,127.0.0.3");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), MultipleNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.MultipleNetaddressStrategy.class);
accessControl.setNetaddress("127.0.0.{1,2,3}");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), MultipleNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.MultipleNetaddressStrategy.class);
accessControl.setNetaddress("127.0.0.1-200");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), RangeNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.RangeNetaddressStrategy.class);
accessControl.setNetaddress("127.0.0.*");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), RangeNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.RangeNetaddressStrategy.class);
accessControl.setNetaddress("127.0.1-20.*");
netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Assert.assertEquals(netaddressStrategy.getClass(), RangeNetaddressStrategy.class);
Assert.assertEquals(netaddressStrategy.getClass(), NetaddressStrategyFactory.RangeNetaddressStrategy.class);
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void verifyTest() {
new OneNetaddressStrategy("127.0.0.1");
new OneNetaddressStrategy("256.0.0.1");
AccessControl accessControl = new AccessControl();
accessControl.setNetaddress("127.0.0.1");
netaddressStrategyFactory.getNetaddressStrategy(accessControl);
accessControl.setNetaddress("256.0.0.1");
netaddressStrategyFactory.getNetaddressStrategy(accessControl);
}
@Test
public void nullNetaddressStrategyTest() {
boolean isMatch = NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY.match(new AccessControl());
boolean isMatch = NetaddressStrategyFactory.NULL_NET_ADDRESS_STRATEGY.match(new AccessControl());
Assert.assertTrue(isMatch);
}
public void oneNetaddressStrategyTest() {
OneNetaddressStrategy netaddressStrategy = new OneNetaddressStrategy("127.0.0.1");
AccessControl accessControl = new AccessControl();
accessControl.setNetaddress("127.0.0.1");
NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
accessControl.setNetaddress("");
boolean match = netaddressStrategy.match(accessControl);
Assert.assertFalse(match);
......@@ -101,7 +105,7 @@ public class NetaddressStrategyTest {
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void multipleNetaddressStrategyExceptionTest() {
AccessControl accessControl = new AccessControl();
accessControl.setNetaddress("127.0.0.1,2,3}");
......@@ -174,17 +178,17 @@ public class NetaddressStrategyTest {
}
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void rangeNetaddressStrategyExceptionStartGreaterEndTest() {
rangeNetaddressStrategyExceptionTest("127.0.0.2-1");
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void rangeNetaddressStrategyExceptionScopeTest() {
rangeNetaddressStrategyExceptionTest("127.0.0.-1-200");
}
@Test(expected = AclPlugAccountAnalysisException.class)
@Test(expected = AclPlugRuntimeException.class)
public void rangeNetaddressStrategyExceptionScopeTwoTest() {
rangeNetaddressStrategyExceptionTest("127.0.0.0-256");
}
......
......@@ -16,19 +16,19 @@
onlyNetAddress:
netaddress: 10.10.103.*
noPermitPullTopic:
- broker-a
- broker-a
list:
- account: RocketMQ
password: 1234567
netaddress: 192.0.0.*
permitSendTopic:
- test1
- test2
- account: RocketMQ
password: 1234567
netaddress: 192.0.2.1
permitSendTopic:
- test3
- test4
- account: RocketMQ
password: 1234567
netaddress: 192.0.0.*
permitSendTopic:
- test1
- test2
- account: RocketMQ
password: 1234567
netaddress: 192.0.2.1
permitSendTopic:
- test3
- test4
\ No newline at end of file
......@@ -32,11 +32,12 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plug.AclPlugController;
import org.apache.rocketmq.acl.plug.AclRemotingServer;
import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.broker.client.ClientHousekeepingService;
import org.apache.rocketmq.broker.client.ConsumerIdsChangeListener;
import org.apache.rocketmq.broker.client.ConsumerManager;
......@@ -515,7 +516,7 @@ public class BrokerController {
@Override
public void doBeforeRequest(String remoteAddr, RemotingCommand request) {
HashMap<String, String> extFields = request.getExtFields();
LoginOrRequestAccessControl accessControl = new LoginOrRequestAccessControl();
AccessControl accessControl = new AccessControl();
accessControl.setCode(request.getCode());
accessControl.setRecognition(remoteAddr);
if (extFields != null) {
......
......@@ -16,7 +16,8 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache</groupId>
......@@ -158,7 +159,7 @@
</executions>
<configuration>
<rules>
<banCircularDependencies />
<banCircularDependencies/>
</rules>
<fail>true</fail>
</configuration>
......@@ -215,9 +216,9 @@
<execution>
<id>generate-effective-dependencies-pom</id>
<phase>generate-resources</phase>
<!-- <goals>
<goals>
<goal>effective-pom</goal>
</goals> -->
</goals>
<configuration>
<output>${project.build.directory}/effective-pom/effective-dependencies.xml</output>
</configuration>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册