From 1d57607641f561380eaa87905c49fd0541093902 Mon Sep 17 00:00:00 2001 From: laohu <8wy118611@163.com> Date: Tue, 20 Nov 2018 02:06:23 +0800 Subject: [PATCH] clean --- .../acl/plug/AccessContralAnalysis.java | 85 ---------- .../rocketmq/acl/plug/AclPlugController.java | 60 ------- .../rocketmq/acl/plug/AclRemotingService.java | 26 --- .../rocketmq/acl/plug/Authentication.java | 59 ------- .../acl/plug/engine/AclPlugEngine.java | 37 ----- ...enticationInfoManagementAclPlugEngine.java | 152 ------------------ .../plug/engine/LoginInfoAclPlugEngine.java | 66 -------- .../entity/BorkerAccessControlTransport.java | 52 ------ .../acl/plug/entity/ControllerParameters.java | 52 ------ .../rocketmq/acl/plug/entity/LoginInfo.java | 82 ---------- .../acl/plug/AclPlugControllerTest.java | 21 --- .../acl/plug/AclRemotingServiceTest.java | 148 ----------------- 12 files changed, 840 deletions(-) delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugController.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/AclRemotingService.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControlTransport.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java delete mode 100644 acl/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java delete mode 100644 acl/src/test/java/org/apache/rocketmq/acl/plug/AclPlugControllerTest.java delete mode 100644 acl/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java deleted file mode 100644 index 1adf6d43..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/AccessContralAnalysis.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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; - -import org.apache.commons.lang3.StringUtils; -import org.apache.rocketmq.acl.plug.entity.AccessControl; -import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -public class AccessContralAnalysis { - - private Map, Map> classTocodeAndMentod = new HashMap<>(); - - private Map fieldNameAndCode = new HashMap<>(); - - public void analysisClass(Class clazz) { - Field[] fields = clazz.getDeclaredFields(); - try { - for (Field field : fields) { - if (field.getType().equals(int.class)) { - String name = StringUtils.replace(field.getName(), "_", "").toLowerCase(); - fieldNameAndCode.put(name, (Integer) field.get(null)); - } - - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new AclPlugRuntimeException(String.format("analysis on failure Class is %s", clazz.getName()), e); - } - } - - public Map analysis(AccessControl accessControl) { - Class clazz = accessControl.getClass(); - Map codeAndField = classTocodeAndMentod.get(clazz); - if (codeAndField == null) { - codeAndField = new HashMap<>(); - Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - if (!field.getType().equals(boolean.class)) - continue; - Integer code = fieldNameAndCode.get(field.getName().toLowerCase()); - if (code == null) { - 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 AclPlugRuntimeException(String.format("AccessControl nonexistent code , name %s", accessControl.getClass().getName())); - } - classTocodeAndMentod.put(clazz, codeAndField); - } - Iterator> it = codeAndField.entrySet().iterator(); - Map authority = new HashMap<>(); - try { - while (it.hasNext()) { - Entry e = it.next(); - authority.put(e.getKey(), (Boolean) e.getValue().get(accessControl)); - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new AclPlugRuntimeException(String.format("analysis on failure AccessControl is %s", AccessControl.class.getName()), e); - } - return authority; - } - -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugController.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugController.java deleted file mode 100644 index 8598e93e..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/AclPlugController.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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; - -import org.apache.rocketmq.acl.PlainAccessValidator; -import org.apache.rocketmq.acl.plug.engine.AclPlugEngine; -import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine; -import org.apache.rocketmq.acl.plug.entity.ControllerParameters; -import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; - -public class AclPlugController { - - private ControllerParameters controllerParameters; - - private AclPlugEngine aclPlugEngine; - - private AclRemotingService aclRemotingService; - - private boolean startSucceed = false; - - public AclPlugController(ControllerParameters controllerParameters) throws AclPlugRuntimeException { - try { - this.controllerParameters = controllerParameters; - aclPlugEngine = new PlainAclPlugEngine(controllerParameters); - aclPlugEngine.initialize(); - aclRemotingService = new PlainAccessValidator(aclPlugEngine); - this.startSucceed = true; - } catch (Exception e) { - throw new AclPlugRuntimeException(String.format("Start the abnormal , Launch parameters is %s", this.controllerParameters.toString()), e); - } - } - - public AclRemotingService getAclRemotingService() { - return this.aclRemotingService; - } - - public void doChannelCloseEvent(String remoteAddr) { - if (this.startSucceed) { - aclPlugEngine.deleteLoginInfo(remoteAddr); - } - } - - public boolean isStartSucceed() { - return startSucceed; - } -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/AclRemotingService.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/AclRemotingService.java deleted file mode 100644 index c651a5d9..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/AclRemotingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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; - -import org.apache.rocketmq.acl.plug.entity.AccessControl; -import org.apache.rocketmq.acl.plug.entity.AuthenticationResult; - -public interface AclRemotingService { - - public AuthenticationResult check(AccessControl accessControl); - -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java deleted file mode 100644 index ae247e72..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/Authentication.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -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; - -public class Authentication { - - public boolean authentication(AuthenticationInfo authenticationInfo, - 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; - } - if (!(authenticationInfo.getAccessControl() instanceof BorkerAccessControl)) { - return true; - } - BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl(); - String topicName = accessControl.getTopic(); - if (code == 10 || code == 310 || code == 320) { - if (borker.getPermitSendTopic().contains(topicName)) { - return true; - } - if (borker.getNoPermitSendTopic().contains(topicName)) { - authenticationResult.setResultString(String.format("noPermitSendTopic include %s", topicName)); - return false; - } - return borker.getPermitSendTopic().isEmpty() ? true : false; - } else if (code == 11) { - if (borker.getPermitPullTopic().contains(topicName)) { - return true; - } - if (borker.getNoPermitPullTopic().contains(topicName)) { - authenticationResult.setResultString(String.format("noPermitPullTopic include %s", topicName)); - return false; - } - return borker.getPermitPullTopic().isEmpty() ? true : false; - } - return true; - } -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java deleted file mode 100644 index d1572755..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AclPlugEngine.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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; - -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; - -public interface AclPlugEngine { - - public AuthenticationInfo getAccessControl(AccessControl accessControl); - - public LoginInfo getLoginInfo(AccessControl accessControl); - - public void deleteLoginInfo(String remoteAddr); - - public AuthenticationResult eachCheckLoginAndAuthentication(AccessControl accessControl); - - public AuthenticationResult eachCheckAuthentication(AccessControl accessControl); - - public void initialize(); -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java deleted file mode 100644 index a6399fc3..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/AuthenticationInfoManagementAclPlugEngine.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.rocketmq.acl.plug.AccessContralAnalysis; -import org.apache.rocketmq.acl.plug.Authentication; -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.BorkerAccessControlTransport; -import org.apache.rocketmq.acl.plug.entity.ControllerParameters; -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; -import org.apache.rocketmq.logging.InternalLogger; -import org.apache.rocketmq.logging.InternalLoggerFactory; - -public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPlugEngine { - - private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.ACL_PLUG_LOGGER_NAME); - ControllerParameters controllerParameters; - private Map> accessControlMap = new HashMap<>(); - private AuthenticationInfo authenticationInfo; - private NetaddressStrategyFactory netaddressStrategyFactory = new NetaddressStrategyFactory(); - private AccessContralAnalysis accessContralAnalysis = new AccessContralAnalysis(); - private Authentication authentication = new Authentication(); - - public AuthenticationInfoManagementAclPlugEngine(ControllerParameters controllerParameters) { - this.controllerParameters = controllerParameters; - accessContralAnalysis.analysisClass(controllerParameters.getAccessContralAnalysisClass()); - } - - public void setAccessControl(AccessControl accessControl) throws AclPlugRuntimeException { - if (accessControl.getAccount() == null || accessControl.getPassword() == null || accessControl.getAccount().length() <= 6 || accessControl.getPassword().length() <= 6) { - 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); - List accessControlAddressList = accessControlMap.get(accessControl.getAccount()); - if (accessControlAddressList == null) { - accessControlAddressList = new ArrayList<>(); - accessControlMap.put(accessControl.getAccount(), accessControlAddressList); - } - AuthenticationInfo authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategy); - accessControlAddressList.add(authenticationInfo); - log.info("authenticationInfo is {}", authenticationInfo.toString()); - } catch (Exception e) { - throw new AclPlugRuntimeException(String.format("Exception info %s %s", e.getMessage(), accessControl.toString()), e); - } - } - - public void setAccessControlList(List accessControlList) throws AclPlugRuntimeException { - for (AccessControl accessControl : accessControlList) { - setAccessControl(accessControl); - } - } - - 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 AclPlugRuntimeException(accessControl.toString(), e); - } - - } - - public AuthenticationInfo getAccessControl(AccessControl accessControl) { - if (accessControl.getAccount() == null && authenticationInfo != null) { - return authenticationInfo.getNetaddressStrategy().match(accessControl) ? authenticationInfo : null; - } else { - List accessControlAddressList = accessControlMap.get(accessControl.getAccount()); - if (accessControlAddressList != null) { - for (AuthenticationInfo ai : accessControlAddressList) { - if (ai.getNetaddressStrategy().match(accessControl) && ai.getAccessControl().getPassword().equals(accessControl.getPassword())) { - return ai; - } - } - } - } - return null; - } - - @Override - public AuthenticationResult eachCheckLoginAndAuthentication(AccessControl accessControl) { - AuthenticationResult authenticationResult = new AuthenticationResult(); - try { - AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl, authenticationResult); - if (authenticationInfo != null) { - boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult); - authenticationResult.setSucceed(boo); - authenticationResult.setAccessControl(authenticationInfo.getAccessControl()); - } - } catch (Exception e) { - authenticationResult.setException(e); - } - return authenticationResult; - } - - public AuthenticationResult eachCheckAuthentication(AccessControl accessControl) { - AuthenticationResult authenticationResult = new AuthenticationResult(); - AuthenticationInfo authenticationInfo = getAccessControl(accessControl); - if (authenticationInfo != null) { - boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult); - authenticationResult.setSucceed(boo); - authenticationResult.setAccessControl(authenticationInfo.getAccessControl()); - } else { - authenticationResult.setResultString("accessControl is null, Please check login, password, IP\""); - } - - - return authenticationResult; - } - - void setBorkerAccessControlTransport(BorkerAccessControlTransport transport) { - if (transport.getOnlyNetAddress() == null && (transport.getList() == null || transport.getList().size() == 0)) { - throw new AclPlugRuntimeException("onlyNetAddress and list can't be all empty"); - } - - if (transport.getOnlyNetAddress() != null) { - this.setNetaddressAccessControl(transport.getOnlyNetAddress()); - } - if (transport.getList() != null || transport.getList().size() > 0) { - for (AccessControl accessControl : transport.getList()) { - this.setAccessControl(accessControl); - } - } - } - - protected abstract AuthenticationInfo getAuthenticationInfo(AccessControl accessControl, - AuthenticationResult authenticationResult); -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java deleted file mode 100644 index 35b56834..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/engine/LoginInfoAclPlugEngine.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -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.ControllerParameters; -import org.apache.rocketmq.acl.plug.entity.LoginInfo; - -public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagementAclPlugEngine { - - private Map loginInfoMap = new ConcurrentHashMap<>(); - - public LoginInfoAclPlugEngine(ControllerParameters controllerParameters) { - super(controllerParameters); - } - - public LoginInfo getLoginInfo(AccessControl accessControl) { - LoginInfo loginInfo = loginInfoMap.get(accessControl.getRecognition()); - if (loginInfo == null) { - AuthenticationInfo authenticationInfo = super.getAccessControl(accessControl); - if (authenticationInfo != null) { - loginInfo = new LoginInfo(); - loginInfo.setAuthenticationInfo(authenticationInfo); - loginInfoMap.put(accessControl.getRecognition(), loginInfo); - } - } - if (loginInfo != null) { - loginInfo.setOperationTime(System.currentTimeMillis()); - } - return loginInfo; - } - - public void deleteLoginInfo(String remoteAddr) { - loginInfoMap.remove(remoteAddr); - } - - protected AuthenticationInfo getAuthenticationInfo(AccessControl accessControl, - AuthenticationResult authenticationResult) { - LoginInfo loginInfo = getLoginInfo(accessControl); - if (loginInfo != null && loginInfo.getAuthenticationInfo() != null) { - return loginInfo.getAuthenticationInfo(); - } - authenticationResult.setResultString("Login information does not exist, Please check login, password, IP"); - return null; - } - -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControlTransport.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControlTransport.java deleted file mode 100644 index 93d00231..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/BorkerAccessControlTransport.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - -import java.util.List; - -public class BorkerAccessControlTransport { - - private BorkerAccessControl onlyNetAddress; - - private List list; - - public BorkerAccessControlTransport() { - super(); - } - - public BorkerAccessControl getOnlyNetAddress() { - return onlyNetAddress; - } - - public void setOnlyNetAddress(BorkerAccessControl onlyNetAddress) { - this.onlyNetAddress = onlyNetAddress; - } - - public List getList() { - return list; - } - - public void setList(List list) { - this.list = list; - } - - @Override - public String toString() { - return "BorkerAccessControlTransport [onlyNetAddress=" + onlyNetAddress + ", list=" + list + "]"; - } - -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java deleted file mode 100644 index 94873b5f..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/ControllerParameters.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - -import org.apache.rocketmq.common.MixAll; -import org.apache.rocketmq.common.protocol.RequestCode; - -public class ControllerParameters { - - private String fileHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); - - private Class accessContralAnalysisClass = RequestCode.class; - - public String getFileHome() { - return fileHome; - } - - public void setFileHome(String fileHome) { - this.fileHome = fileHome; - } - - public Class getAccessContralAnalysisClass() { - return accessContralAnalysisClass; - } - - public void setAccessContralAnalysisClass(Class accessContralAnalysisClass) { - this.accessContralAnalysisClass = accessContralAnalysisClass; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ControllerParametersEntity [fileHome=").append(fileHome).append(", accessContralAnalysisClass=") - .append(accessContralAnalysisClass).append("]"); - return builder.toString(); - } - -} diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java b/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java deleted file mode 100644 index df1166be..00000000 --- a/acl/src/main/java/org/apache/rocketmq/acl/plug/entity/LoginInfo.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class LoginInfo { - - private String recognition; - - private long loginTime = System.currentTimeMillis(); - - private volatile long operationTime = loginTime; - - private volatile AtomicBoolean clear = new AtomicBoolean(); - - private AuthenticationInfo authenticationInfo; - - public AuthenticationInfo getAuthenticationInfo() { - return authenticationInfo; - } - - public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) { - this.authenticationInfo = authenticationInfo; - } - - public String getRecognition() { - return recognition; - } - - public void setRecognition(String recognition) { - this.recognition = recognition; - } - - public long getLoginTime() { - return loginTime; - } - - public void setLoginTime(long loginTime) { - this.loginTime = loginTime; - } - - public long getOperationTime() { - return operationTime; - } - - public void setOperationTime(long operationTime) { - this.operationTime = operationTime; - } - - public AtomicBoolean getClear() { - return clear; - } - - 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(); - } - -} diff --git a/acl/src/test/java/org/apache/rocketmq/acl/plug/AclPlugControllerTest.java b/acl/src/test/java/org/apache/rocketmq/acl/plug/AclPlugControllerTest.java deleted file mode 100644 index 223cbc7c..00000000 --- a/acl/src/test/java/org/apache/rocketmq/acl/plug/AclPlugControllerTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 AclPlugControllerTest { - -} diff --git a/acl/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java b/acl/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java deleted file mode 100644 index 37aa38b5..00000000 --- a/acl/src/test/java/org/apache/rocketmq/acl/plug/AclRemotingServiceTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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; - -import java.util.HashMap; - -import org.apache.rocketmq.acl.AccessResource; -import org.apache.rocketmq.acl.AccessValidator; -import org.apache.rocketmq.acl.PlainAccessValidator; -import org.apache.rocketmq.acl.plug.entity.AccessControl; -import org.apache.rocketmq.acl.plug.entity.AuthenticationResult; -import org.apache.rocketmq.acl.plug.entity.BorkerAccessControl; -import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test;; - -public class AclRemotingServiceTest { - - - AclRemotingService defaultAclService; - - AccessValidator accessValidator; - - AccessControl accessControl; - - AccessControl accessControlTwo; - - @Before - public void init() { - System.setProperty("rocketmq.home.dir", "src/test/resources"); - PlainAccessValidator aclRemotingServiceImpl = new PlainAccessValidator(); - defaultAclService = aclRemotingServiceImpl; - accessValidator = aclRemotingServiceImpl; - - accessControl = new BorkerAccessControl(); - accessControl.setAccount("RocketMQ"); - accessControl.setPassword("1234567"); - accessControl.setNetaddress("192.0.0.1"); - accessControl.setRecognition("127.0.0.1:1"); - - accessControlTwo = new BorkerAccessControl(); - accessControlTwo.setAccount("RocketMQ"); - accessControlTwo.setPassword("1234567"); - accessControlTwo.setNetaddress("192.0.2.1"); - accessControlTwo.setRecognition("127.0.0.1:2"); - } - - - @Test - public void defaultConstructorTest() { - System.setProperty("rocketmq.home.dir", "src/test/resources"); - AclRemotingService defaultAclService = new PlainAccessValidator(); - Assert.assertNotNull(defaultAclService); - } - - @Test - public void parseTest() { - RemotingCommand remotingCommand = RemotingCommand.createResponseCommand(34, ""); - HashMap map = new HashMap<>(); - map.put("account", "RocketMQ"); - map.put("password", "123456"); - map.put("topic", "test"); - remotingCommand.setExtFields(map); - - AccessResource accessResource = accessValidator.parse(remotingCommand, "127.0.0.1:123"); - AccessControl accessControl = (AccessControl) accessResource; - AccessControl newAccessControl = new AccessControl(); - newAccessControl.setAccount("RocketMQ"); - newAccessControl.setPassword("123456"); - newAccessControl.setTopic("test"); - newAccessControl.setCode(34); - newAccessControl.setNetaddress("127.0.0.1"); - newAccessControl.setRecognition("127.0.0.1:123"); - Assert.assertEquals(accessControl.toString(), newAccessControl.toString()); - } - - @Test - public void checkTest() { - accessControl.setCode(34); - AuthenticationResult authenticationResult = defaultAclService.check(accessControl); - Assert.assertTrue(authenticationResult.isSucceed()); - } - - @Test(expected = AclPlugRuntimeException.class) - public void checkAccessExceptionTest() { - accessControl.setCode(34); - accessControl.setAccount("Rocketmq"); - defaultAclService.check(accessControl); - } - - @Test(expected = AclPlugRuntimeException.class) - public void checkPasswordTest() { - accessControl.setCode(34); - accessControl.setPassword("123123123"); - defaultAclService.check(accessControl); - } - - @Test(expected = AclPlugRuntimeException.class) - public void checkCodeTest() { - accessControl.setCode(14434); - accessControl.setPassword("123123123"); - defaultAclService.check(accessControl); - } - - - @Test - public void validateTest() { - accessControl.setCode(34); - accessValidator.validate(accessControl); - } - - @Test(expected = AclPlugRuntimeException.class) - public void validateAccessExceptionTest() { - accessControl.setCode(34); - accessControl.setAccount("Rocketmq"); - accessValidator.validate(accessControl); - } - - @Test(expected = AclPlugRuntimeException.class) - public void validatePasswordTest() { - accessControl.setCode(34); - accessControl.setPassword("123123123"); - accessValidator.validate(accessControl); - } - - @Test(expected = AclPlugRuntimeException.class) - public void validateCodeTest() { - accessControl.setCode(14434); - accessControl.setPassword("123123123"); - accessValidator.validate(accessControl); - } -} -- GitLab