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

accomplish

上级 9e0021db
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rocketmq-logging</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rocketmq-common</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -13,7 +29,7 @@ public class AccessContralAnalysis { ...@@ -13,7 +29,7 @@ public class AccessContralAnalysis {
private Map<Class<?>, Map<Integer, Field>> classTocodeAndMentod = new HashMap<>(); private Map<Class<?>, Map<Integer, Field>> classTocodeAndMentod = new HashMap<>();
public Map<Integer , Boolean> analysis(AccessControl accessControl) { public Map<Integer, Boolean> analysis(AccessControl accessControl) {
Class<? extends AccessControl> clazz = accessControl.getClass(); Class<? extends AccessControl> clazz = accessControl.getClass();
Map<Integer, Field> codeAndField = classTocodeAndMentod.get(clazz); Map<Integer, Field> codeAndField = classTocodeAndMentod.get(clazz);
if (codeAndField == null) { if (codeAndField == null) {
...@@ -39,7 +55,7 @@ public class AccessContralAnalysis { ...@@ -39,7 +55,7 @@ public class AccessContralAnalysis {
try { try {
while (it.hasNext()) { while (it.hasNext()) {
Entry<Integer, Field> e = it.next(); Entry<Integer, Field> e = it.next();
authority.put(e.getKey(), (Boolean)e.getValue().get(accessControl)); authority.put(e.getKey(), (Boolean) e.getValue().get(accessControl));
} }
} catch (IllegalArgumentException | IllegalAccessException e1) { } catch (IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace(); e1.printStackTrace();
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine; import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine; import org.apache.rocketmq.acl.plug.engine.PlainAclPlugEngine;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity; import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.exception.AclPlugStartException;
public class AclPlugController { public class AclPlugController {
private ControllerParametersEntity controllerParametersEntity; private ControllerParametersEntity controllerParametersEntity;
private AclPlugEngine aclPlugEngine; private AclPlugEngine aclPlugEngine;
private AclRemotingServer aclRemotingServer; private AclRemotingServer aclRemotingServer;
public AclPlugController(ControllerParametersEntity controllerParametersEntity){ private boolean startSucceed = false;
public AclPlugController(ControllerParametersEntity controllerParametersEntity) throws AclPlugStartException {
try {
this.controllerParametersEntity = controllerParametersEntity; this.controllerParametersEntity = controllerParametersEntity;
aclPlugEngine = new PlainAclPlugEngine(); aclPlugEngine = new PlainAclPlugEngine(controllerParametersEntity);
aclRemotingServer = new DefaultAclRemotingServerImpl(aclPlugEngine); 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);
}
} }
public AclRemotingServer getAclRemotingServer() { public AclRemotingServer getAclRemotingServer() {
return this.aclRemotingServer; return this.aclRemotingServer;
} }
public void doChannelCloseEvent(String remoteAddr) {
aclPlugEngine.deleteLoginInfo(remoteAddr);
}
public boolean isStartSucceed() { public boolean isStartSucceed() {
return true; return startSucceed;
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
public class AclPlugServer { public class AclPlugServer {
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo; import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclRemotingServer { public interface AclRemotingServer {
public AuthenticationInfo login(); public AuthenticationInfo login();
public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl);
public AuthenticationInfo eachCheck(LoginOrRequestAccessControl accessControl);
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class AclUtils { public class AclUtils {
public static String[] getAddreeStrArray(String netaddress, String four) {
public static String[] getAddreeStrArray(String netaddress ,String four ) { String[] fourStrArray = StringUtils.split(four.substring(1, four.length() - 1), ",");
String[] fourStrArray = StringUtils.split(four.substring(1, four.length()-1) , ","); String address = netaddress.substring(0, netaddress.indexOf("{"));
String address = netaddress.substring(0, netaddress.indexOf("{") ); String[] addreeStrArray = new String[fourStrArray.length];
String[] addreeStrArray = new String[ fourStrArray.length ]; for (int i = 0; i < fourStrArray.length; i++) {
for(int i = 0 ; i < fourStrArray.length ; i++) { addreeStrArray[i] = address + fourStrArray[i];
addreeStrArray[i] = address+fourStrArray[i];
} }
return addreeStrArray; return addreeStrArray;
} }
public static boolean isScope(String num, int index) { public static boolean isScope(String num, int index) {
String[] strArray = StringUtils.split(num , "."); String[] strArray = StringUtils.split(num, ".");
if(strArray.length != 4) { if (strArray.length != 4) {
return false; return false;
} }
return isScope(strArray, index); return isScope(strArray, index);
...@@ -29,7 +44,7 @@ public class AclUtils { ...@@ -29,7 +44,7 @@ public class AclUtils {
} }
for (int i = 0; i < index; i++) { for (int i = 0; i < index; i++) {
if( !isScope(num[i])) { if (!isScope(num[i])) {
return false; return false;
} }
} }
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -8,11 +24,15 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; ...@@ -8,11 +24,15 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public class Authentication { public class Authentication {
public boolean authentication(AuthenticationInfo authenticationInfo, LoginOrRequestAccessControl loginOrRequestAccessControl,AuthenticationResult authenticationResult) { public boolean authentication(AuthenticationInfo authenticationInfo,
LoginOrRequestAccessControl loginOrRequestAccessControl, AuthenticationResult authenticationResult) {
int code = loginOrRequestAccessControl.getCode(); int code = loginOrRequestAccessControl.getCode();
if (authenticationInfo.getAuthority().get(code)) { if (!authenticationInfo.getAuthority().get(code)) {
authenticationResult.setResultString(String.format("code is %d Authentication failed", code));
return false;
}
AccessControl accessControl = authenticationInfo.getAccessControl(); AccessControl accessControl = authenticationInfo.getAccessControl();
if( !(accessControl instanceof BorkerAccessControl)) { if (!(accessControl instanceof BorkerAccessControl)) {
return true; return true;
} }
BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl(); BorkerAccessControl borker = (BorkerAccessControl) authenticationInfo.getAccessControl();
...@@ -38,6 +58,4 @@ public class Authentication { ...@@ -38,6 +58,4 @@ public class Authentication {
} }
return true; 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; package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.engine.AclPlugEngine; import org.apache.rocketmq.acl.plug.engine.AclPlugEngine;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo; import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAuthenticationException;
import org.apache.rocketmq.acl.plug.exception.AclPlugLoginException;
import org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException;
public class DefaultAclRemotingServerImpl implements AclRemotingServer { public class DefaultAclRemotingServerImpl implements AclRemotingServer {
private AclPlugEngine aclPlugEngine; private AclPlugEngine aclPlugEngine;
public DefaultAclRemotingServerImpl(AclPlugEngine aclPlugEngine ) { public DefaultAclRemotingServerImpl(AclPlugEngine aclPlugEngine) {
this.aclPlugEngine = aclPlugEngine; this.aclPlugEngine = aclPlugEngine;
} }
...@@ -19,9 +39,18 @@ public class DefaultAclRemotingServerImpl implements AclRemotingServer { ...@@ -19,9 +39,18 @@ public class DefaultAclRemotingServerImpl implements AclRemotingServer {
} }
@Override @Override
public AuthenticationInfo eachCheck(LoginOrRequestAccessControl accessControl) { public AuthenticationResult eachCheck(LoginOrRequestAccessControl accessControl) {
aclPlugEngine.eachCheckLoginAndAuthentication(accessControl); AuthenticationResult authenticationResult = aclPlugEngine.eachCheckLoginAndAuthentication(accessControl);
return null; if (authenticationResult.getException() != null) {
throw new AclPlugRuntimeException(String.format("eachCheck the inspection appear exception, accessControl data is %s", accessControl.toString()), authenticationResult.getException());
}
if (authenticationResult.getAccessControl() == null) {
throw new AclPlugLoginException(String.format("%s accessControl data is %s", authenticationResult.getResultString(), accessControl.toString()));
}
if (!authenticationResult.isSucceed()) {
throw new AclPlugAuthenticationException(String.format("%s accessControl data is %s", authenticationResult.getResultString(), accessControl.toString()));
}
return authenticationResult;
} }
} }
package org.apache.rocketmq.acl.plug;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
public class EmptyImplementationAclRemotingServer implements AclRemotingServer {
@Override
public AuthenticationInfo login() {
return null;
}
@Override
public AuthenticationInfo eachCheck() {
// TODO Auto-generated method stub
return null;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.annotation; package org.apache.rocketmq.acl.plug.annotation;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -8,9 +24,11 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; ...@@ -8,9 +24,11 @@ import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
public interface AclPlugEngine { public interface AclPlugEngine {
public AuthenticationInfo getAccessControl(AccessControl accessControl) ; public AuthenticationInfo getAccessControl(AccessControl accessControl);
public LoginInfo getLoginInfo(AccessControl accessControl) ; public LoginInfo getLoginInfo(AccessControl accessControl);
public void deleteLoginInfo(String remoteAddr);
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl); public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl);
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.util.HashMap; import java.util.HashMap;
...@@ -10,13 +26,18 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -10,13 +26,18 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo; import org.apache.rocketmq.acl.plug.entity.AuthenticationInfo;
import org.apache.rocketmq.acl.plug.entity.AuthenticationResult; import org.apache.rocketmq.acl.plug.entity.AuthenticationResult;
import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl; import org.apache.rocketmq.acl.plug.entity.LoginOrRequestAccessControl;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategyFactory;
import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.InternalLogger;
import org.apache.rocketmq.logging.InternalLoggerFactory;
public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPlugEngine { public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPlugEngine {
private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.ACL_PLUG_LOGGER_NAME);
private Map<String/**account **/ , Map<String/**netaddress**/ , AuthenticationInfo>> accessControlMap = new HashMap<>(); private Map<String/** account **/, Map<String/** netaddress **/, AuthenticationInfo>> accessControlMap = new HashMap<>();
private AuthenticationInfo authenticationInfo; private AuthenticationInfo authenticationInfo;
...@@ -26,41 +47,48 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl ...@@ -26,41 +47,48 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
private Authentication authentication = new Authentication(); private Authentication authentication = new Authentication();
public void setAccessControl(AccessControl accessControl) { public void setAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
try { try {
NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl); NetaddressStrategy netaddressStrategy = netaddressStrategyFactory.getNetaddressStrategy(accessControl);
Map<String , AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount()); Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount());
if(accessControlAddressMap == null ) { if (accessControlAddressMap == null) {
accessControlAddressMap = new HashMap<>(); accessControlAddressMap = new HashMap<>();
accessControlMap.put(accessControl.getAccount(), accessControlAddressMap); accessControlMap.put(accessControl.getAccount(), accessControlAddressMap);
} }
accessControlAddressMap.put(accessControl.getNetaddress(), new AuthenticationInfo(accessContralAnalysis.analysis(accessControl),accessControl ,netaddressStrategy)); AuthenticationInfo authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl), accessControl, netaddressStrategy);
}catch(Exception e) { accessControlAddressMap.put(accessControl.getNetaddress(), authenticationInfo);
// TODO Exception log.info("authenticationInfo is {}", authenticationInfo.toString());
} catch (Exception e) {
throw new AclPlugAccountAnalysisException(accessControl.toString(), e);
} }
} }
public void setAccessControlList(List<AccessControl> AccessControlList) { public void setAccessControlList(List<AccessControl> accessControlList) throws AclPlugAccountAnalysisException {
for(AccessControl accessControl : AccessControlList) { for (AccessControl accessControl : accessControlList) {
setAccessControl(accessControl); setAccessControl(accessControl);
} }
} }
public void setNetaddressAccessControl(AccessControl accessControl) throws AclPlugAccountAnalysisException {
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);
}
public void setNetaddressAccessControl(AccessControl accessControl) {
authenticationInfo = new AuthenticationInfo(accessContralAnalysis.analysis(accessControl) , accessControl, netaddressStrategyFactory.getNetaddressStrategy(accessControl));
} }
public AuthenticationInfo getAccessControl(AccessControl accessControl) { public AuthenticationInfo getAccessControl(AccessControl accessControl) {
AuthenticationInfo existing = null; AuthenticationInfo existing = null;
if( accessControl.getAccount() == null && authenticationInfo != null) { if (accessControl.getAccount() == null && authenticationInfo != null) {
existing = authenticationInfo.getNetaddressStrategy().match(accessControl)?authenticationInfo:null; existing = authenticationInfo.getNetaddressStrategy().match(accessControl) ? authenticationInfo : null;
}else { } else {
Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount()); Map<String, AuthenticationInfo> accessControlAddressMap = accessControlMap.get(accessControl.getAccount());
if(accessControlAddressMap != null ) { if (accessControlAddressMap != null) {
existing = accessControlAddressMap.get(accessControl.getNetaddress()); existing = accessControlAddressMap.get(accessControl.getNetaddress());
if(existing.getAccessControl().getPassword().equals(accessControl.getPassword())) { if (existing.getAccessControl().getPassword().equals(accessControl.getPassword())) {
if( existing.getNetaddressStrategy().match(accessControl)) { if (existing.getNetaddressStrategy().match(accessControl)) {
return existing; return existing;
} }
} }
...@@ -73,13 +101,18 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl ...@@ -73,13 +101,18 @@ public abstract class AuthenticationInfoManagementAclPlugEngine implements AclPl
@Override @Override
public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl) { public AuthenticationResult eachCheckLoginAndAuthentication(LoginOrRequestAccessControl accessControl) {
AuthenticationResult authenticationResult = new AuthenticationResult(); AuthenticationResult authenticationResult = new AuthenticationResult();
AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl , authenticationResult); try {
if(authenticationInfo != null) { AuthenticationInfo authenticationInfo = getAuthenticationInfo(accessControl, authenticationResult);
boolean boo = authentication.authentication(authenticationInfo, accessControl,authenticationResult); if (authenticationInfo != null) {
authenticationResult.setSucceed( boo ); boolean boo = authentication.authentication(authenticationInfo, accessControl, authenticationResult);
authenticationResult.setSucceed(boo);
}
} catch (Exception e) {
authenticationResult.setException(e);
} }
return authenticationResult; return authenticationResult;
} }
protected abstract AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl , AuthenticationResult authenticationResult); protected abstract AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
AuthenticationResult authenticationResult);
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.util.Map; import java.util.Map;
...@@ -16,16 +32,17 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen ...@@ -16,16 +32,17 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen
@Override @Override
public AuthenticationInfo getAccessControl(AccessControl accessControl) { public AuthenticationInfo getAccessControl(AccessControl accessControl) {
AuthenticationInfo authenticationInfo = super.getAccessControl(accessControl); AuthenticationInfo authenticationInfo = super.getAccessControl(accessControl);
if (authenticationInfo != null) {
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setAuthenticationInfo(authenticationInfo); loginInfo.setAuthenticationInfo(authenticationInfo);
loginInfoMap.put(accessControl.getRecognition(), loginInfo); loginInfoMap.put(accessControl.getRecognition(), loginInfo);
}
return authenticationInfo; return authenticationInfo;
} }
public LoginInfo getLoginInfo(AccessControl accessControl) { public LoginInfo getLoginInfo(AccessControl accessControl) {
LoginInfo loginInfo = loginInfoMap.get(accessControl.getRecognition()); LoginInfo loginInfo = loginInfoMap.get(accessControl.getRecognition());
if (loginInfo == null) { if (loginInfo == null && getAccessControl(accessControl) != null) {
getAccessControl(accessControl);
loginInfo = loginInfoMap.get(accessControl.getRecognition()); loginInfo = loginInfoMap.get(accessControl.getRecognition());
} }
if (loginInfo != null) { if (loginInfo != null) {
...@@ -34,14 +51,19 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen ...@@ -34,14 +51,19 @@ public abstract class LoginInfoAclPlugEngine extends AuthenticationInfoManagemen
return loginInfo; return loginInfo;
} }
public void deleteLoginInfo(String remoteAddr) {
loginInfoMap.remove(remoteAddr);
}
protected AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl , AuthenticationResult authenticationResult) { protected AuthenticationInfo getAuthenticationInfo(LoginOrRequestAccessControl accessControl,
AuthenticationResult authenticationResult) {
LoginInfo anthenticationInfo = getLoginInfo(accessControl); LoginInfo anthenticationInfo = getLoginInfo(accessControl);
if(anthenticationInfo != null) { if (anthenticationInfo != null && anthenticationInfo.getAuthenticationInfo() != null) {
return anthenticationInfo.getAuthenticationInfo(); return anthenticationInfo.getAuthenticationInfo();
}else { } else {
authenticationResult.setResultString("Login information does not exist"); authenticationResult.setResultString("Login information does not exist, Please check login, password, IP");
} }
return null; return null;
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.engine; package org.apache.rocketmq.acl.plug.engine;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport; import org.apache.rocketmq.acl.plug.entity.BorkerAccessControlTransport;
import org.apache.rocketmq.acl.plug.entity.ControllerParametersEntity;
import org.apache.rocketmq.acl.plug.exception.AclPlugAccountAnalysisException;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
public class PlainAclPlugEngine extends LoginInfoAclPlugEngine { public class PlainAclPlugEngine extends LoginInfoAclPlugEngine {
public PlainAclPlugEngine() { private ControllerParametersEntity controllerParametersEntity;
public PlainAclPlugEngine(
ControllerParametersEntity controllerParametersEntity) throws AclPlugAccountAnalysisException {
this.controllerParametersEntity = controllerParametersEntity;
init(); init();
} }
void init() { void init() throws AclPlugAccountAnalysisException {
String filePath = controllerParametersEntity.getFileHome() + "/conf/transport.yml";
Yaml ymal = new Yaml(); Yaml ymal = new Yaml();
BorkerAccessControlTransport transport = ymal.loadAs(PlainAclPlugEngine.class.getClassLoader().getResourceAsStream( "transport.yml"), BorkerAccessControlTransport.class); FileInputStream fis;
try {
fis = new FileInputStream(new File(filePath));
BorkerAccessControlTransport transport = ymal.loadAs(fis, BorkerAccessControlTransport.class);
super.setNetaddressAccessControl(transport.getOnlyNetAddress()); super.setNetaddressAccessControl(transport.getOnlyNetAddress());
for(AccessControl accessControl : transport.getList()) { for (AccessControl accessControl : transport.getList()) {
super.setAccessControl(accessControl); super.setAccessControl(accessControl);
} }
} catch (FileNotFoundException e) {
throw new AclPlugAccountAnalysisException("The transport.yml file for Plain mode was not found", e);
}
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class AccessControl { public class AccessControl {
...@@ -13,7 +29,6 @@ public class AccessControl { ...@@ -13,7 +29,6 @@ public class AccessControl {
public AccessControl() { public AccessControl() {
} }
public String getAccount() { public String getAccount() {
return account; return account;
} }
...@@ -52,6 +67,4 @@ public class AccessControl { ...@@ -52,6 +67,4 @@ public class AccessControl {
+ ", recognition=" + recognition + "]"; + ", recognition=" + recognition + "]";
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy; import org.apache.rocketmq.acl.plug.strategy.NetaddressStrategy;
...@@ -12,7 +30,8 @@ public class AuthenticationInfo { ...@@ -12,7 +30,8 @@ public class AuthenticationInfo {
private Map<Integer, Boolean> authority; private Map<Integer, Boolean> authority;
public AuthenticationInfo(Map<Integer, Boolean> authority , AccessControl accessControl, NetaddressStrategy netaddressStrategy) { public AuthenticationInfo(Map<Integer, Boolean> authority, AccessControl accessControl,
NetaddressStrategy netaddressStrategy) {
super(); super();
this.authority = authority; this.authority = authority;
this.accessControl = accessControl; this.accessControl = accessControl;
...@@ -35,8 +54,6 @@ public class AuthenticationInfo { ...@@ -35,8 +54,6 @@ public class AuthenticationInfo {
this.netaddressStrategy = netaddressStrategy; this.netaddressStrategy = netaddressStrategy;
} }
public Map<Integer, Boolean> getAuthority() { public Map<Integer, Boolean> getAuthority() {
return authority; return authority;
} }
...@@ -47,10 +64,18 @@ public class AuthenticationInfo { ...@@ -47,10 +64,18 @@ public class AuthenticationInfo {
@Override @Override
public String toString() { public String toString() {
return "AuthenticationInfo [accessControl=" + accessControl + ", netaddressStrategy=" + netaddressStrategy StringBuilder builder = new StringBuilder();
+ ", authority=" + authority + "]"; builder.append("AuthenticationInfo [accessControl=").append(accessControl).append(", netaddressStrategy=")
.append(netaddressStrategy).append(", authority={");
Iterator<Entry<Integer, Boolean>> it = authority.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, Boolean> e = it.next();
if (!e.getValue()) {
builder.append(e.getKey().toString()).append(":").append(e.getValue()).append(",");
}
}
builder.append("}]");
return builder.toString();
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class AuthenticationResult { public class AuthenticationResult {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.HashSet; import java.util.HashSet;
...@@ -5,17 +21,13 @@ import java.util.Set; ...@@ -5,17 +21,13 @@ import java.util.Set;
import org.apache.rocketmq.acl.plug.annotation.RequestCode; import org.apache.rocketmq.acl.plug.annotation.RequestCode;
/**
* @author Administrator public class BorkerAccessControl extends AccessControl {
*
*/
public class BorkerAccessControl extends AccessControl{
public BorkerAccessControl() { public BorkerAccessControl() {
} }
private Set<String> permitSendTopic = new HashSet<>(); private Set<String> permitSendTopic = new HashSet<>();
private Set<String> noPermitSendTopic = new HashSet<>(); private Set<String> noPermitSendTopic = new HashSet<>();
...@@ -70,7 +82,7 @@ public class BorkerAccessControl extends AccessControl{ ...@@ -70,7 +82,7 @@ public class BorkerAccessControl extends AccessControl{
private boolean updateAndCreateTopic = true; private boolean updateAndCreateTopic = true;
@RequestCode(code = 215) @RequestCode(code = 215)
private boolean deleteTopicInbroker =true; private boolean deleteTopicInbroker = true;
@RequestCode(code = 21) @RequestCode(code = 21)
private boolean getAllTopicConfig = true; private boolean getAllTopicConfig = true;
...@@ -171,9 +183,6 @@ public class BorkerAccessControl extends AccessControl{ ...@@ -171,9 +183,6 @@ public class BorkerAccessControl extends AccessControl{
@RequestCode(code = 321) @RequestCode(code = 321)
private boolean queryConsumeQueue = true; private boolean queryConsumeQueue = true;
public Set<String> getPermitSendTopic() { public Set<String> getPermitSendTopic() {
return permitSendTopic; return permitSendTopic;
} }
...@@ -600,35 +609,110 @@ public class BorkerAccessControl extends AccessControl{ ...@@ -600,35 +609,110 @@ public class BorkerAccessControl extends AccessControl{
@Override @Override
public String toString() { public String toString() {
return "BorkerAccessControl [permitSendTopic=" + permitSendTopic + ", noPermitSendTopic=" + noPermitSendTopic StringBuilder builder = new StringBuilder();
+ ", permitPullTopic=" + permitPullTopic + ", noPermitPullTopic=" + noPermitPullTopic + ", sendMessage=" builder.append("BorkerAccessControl [permitSendTopic=").append(permitSendTopic).append(", noPermitSendTopic=")
+ sendMessage + ", sendMessageV2=" + sendMessageV2 + ", sendBatchMessage=" + sendBatchMessage .append(noPermitSendTopic).append(", permitPullTopic=").append(permitPullTopic)
+ ", consumerSendMsgBack=" + consumerSendMsgBack + ", pullMessage=" + pullMessage + ", queryMessage=" .append(", noPermitPullTopic=").append(noPermitPullTopic);
+ queryMessage + ", viewMessageById=" + viewMessageById + ", heartBeat=" + heartBeat if (!!sendMessage)
+ ", unregisterClient=" + unregisterClient + ", checkClientConfig=" + checkClientConfig builder.append(", sendMessage=").append(sendMessage);
+ ", getConsumerListByGroup=" + getConsumerListByGroup + ", updateConsumerOffset=" if (!!sendMessageV2)
+ updateConsumerOffset + ", queryConsumerOffset=" + queryConsumerOffset + ", endTransaction=" builder.append(", sendMessageV2=").append(sendMessageV2);
+ endTransaction + ", updateAndCreateTopic=" + updateAndCreateTopic + ", deleteTopicInbroker=" if (!sendBatchMessage)
+ deleteTopicInbroker + ", getAllTopicConfig=" + getAllTopicConfig + ", updateBrokerConfig=" builder.append(", sendBatchMessage=").append(sendBatchMessage);
+ updateBrokerConfig + ", getBrokerConfig=" + getBrokerConfig + ", searchOffsetByTimestamp=" if (!consumerSendMsgBack)
+ searchOffsetByTimestamp + ", getMaxOffset=" + getMaxOffset + ", getMixOffset=" + getMixOffset builder.append(", consumerSendMsgBack=").append(consumerSendMsgBack);
+ ", getEarliestMsgStoretime=" + getEarliestMsgStoretime + ", getBrokerRuntimeInfo=" if (!pullMessage)
+ getBrokerRuntimeInfo + ", lockBatchMQ=" + lockBatchMQ + ", unlockBatchMQ=" + unlockBatchMQ builder.append(", pullMessage=").append(pullMessage);
+ ", updateAndCreteSubscriptiongroup=" + updateAndCreteSubscriptiongroup if (!queryMessage)
+ ", getAllSubscriptiongroupConfig=" + getAllSubscriptiongroupConfig + ", deleteSubscriptiongroup=" builder.append(", queryMessage=").append(queryMessage);
+ deleteSubscriptiongroup + ", getTopicStatsInfo=" + getTopicStatsInfo + ", getConsumerConnectionList=" if (!viewMessageById)
+ getConsumerConnectionList + ", getProducerConnectionList=" + getProducerConnectionList builder.append(", viewMessageById=").append(viewMessageById);
+ ", getConsumeStats=" + getConsumeStats + ", getAllConsumerOffset=" + getAllConsumerOffset if (!heartBeat)
+ ", getAllDelayOffset=" + getAllDelayOffset + ", invokeBrokerToresetOffset=" builder.append(", heartBeat=").append(heartBeat);
+ invokeBrokerToresetOffset + ", queryTopicConsumByWho=" + queryTopicConsumByWho if (!unregisterClient)
+ ", registerFilterServer=" + registerFilterServer + ", queryConsumeTimeSpan=" + queryConsumeTimeSpan builder.append(", unregisterClient=").append(unregisterClient);
+ ", getSystemTopicListFromBroker=" + getSystemTopicListFromBroker + ", cleanExpiredConsumequeue=" if (!checkClientConfig)
+ cleanExpiredConsumequeue + ", cleanUnusedTopic=" + cleanUnusedTopic + ", getConsumerRunningInfo=" builder.append(", checkClientConfig=").append(checkClientConfig);
+ getConsumerRunningInfo + ", queryCorrectionOffset=" + queryCorrectionOffset if (!getConsumerListByGroup)
+ ", consumeMessageDirectly=" + consumeMessageDirectly + ", cloneGroupOffset=" + cloneGroupOffset builder.append(", getConsumerListByGroup=").append(getConsumerListByGroup);
+ ", viewBrokerStatsData=" + viewBrokerStatsData + ", getBrokerConsumeStats=" + getBrokerConsumeStats if (!updateConsumerOffset)
+ ", queryConsumeQueue=" + queryConsumeQueue + ", toString()=" + super.toString() + "]"; builder.append(", updateConsumerOffset=").append(updateConsumerOffset);
if (!queryConsumerOffset)
builder.append(", queryConsumerOffset=").append(queryConsumerOffset);
if (!endTransaction)
builder.append(", endTransaction=").append(endTransaction);
if (!updateAndCreateTopic)
builder.append(", updateAndCreateTopic=").append(updateAndCreateTopic);
if (!deleteTopicInbroker)
builder.append(", deleteTopicInbroker=").append(deleteTopicInbroker);
if (!getAllTopicConfig)
builder.append(", getAllTopicConfig=").append(getAllTopicConfig);
if (!updateBrokerConfig)
builder.append(", updateBrokerConfig=").append(updateBrokerConfig);
if (!getBrokerConfig)
builder.append(", getBrokerConfig=").append(getBrokerConfig);
if (!searchOffsetByTimestamp)
builder.append(", searchOffsetByTimestamp=").append(searchOffsetByTimestamp);
if (!getMaxOffset)
builder.append(", getMaxOffset=").append(getMaxOffset);
if (!getMixOffset)
builder.append(", getMixOffset=").append(getMixOffset);
if (!getEarliestMsgStoretime)
builder.append(", getEarliestMsgStoretime=").append(getEarliestMsgStoretime);
if (!getBrokerRuntimeInfo)
builder.append(", getBrokerRuntimeInfo=").append(getBrokerRuntimeInfo);
if (!lockBatchMQ)
builder.append(", lockBatchMQ=").append(lockBatchMQ);
if (!unlockBatchMQ)
builder.append(", unlockBatchMQ=").append(unlockBatchMQ);
if (!updateAndCreteSubscriptiongroup)
builder.append(", updateAndCreteSubscriptiongroup=").append(updateAndCreteSubscriptiongroup);
if (!getAllSubscriptiongroupConfig)
builder.append(", getAllSubscriptiongroupConfig=").append(getAllSubscriptiongroupConfig);
if (!deleteSubscriptiongroup)
builder.append(", deleteSubscriptiongroup=").append(deleteSubscriptiongroup);
if (!getTopicStatsInfo)
builder.append(", getTopicStatsInfo=").append(getTopicStatsInfo);
if (!getConsumerConnectionList)
builder.append(", getConsumerConnectionList=").append(getConsumerConnectionList);
if (!getProducerConnectionList)
builder.append(", getProducerConnectionList=").append(getProducerConnectionList);
if (!getConsumeStats)
builder.append(", getConsumeStats=").append(getConsumeStats);
if (!getAllConsumerOffset)
builder.append(", getAllConsumerOffset=").append(getAllConsumerOffset);
if (!getAllDelayOffset)
builder.append(", getAllDelayOffset=").append(getAllDelayOffset);
if (!invokeBrokerToresetOffset)
builder.append(", invokeBrokerToresetOffset=").append(invokeBrokerToresetOffset);
if (!queryTopicConsumByWho)
builder.append(", queryTopicConsumByWho=").append(queryTopicConsumByWho);
if (!registerFilterServer)
builder.append(", registerFilterServer=").append(registerFilterServer);
if (!queryConsumeTimeSpan)
builder.append(", queryConsumeTimeSpan=").append(queryConsumeTimeSpan);
if (!getSystemTopicListFromBroker)
builder.append(", getSystemTopicListFromBroker=").append(getSystemTopicListFromBroker);
if (!cleanExpiredConsumequeue)
builder.append(", cleanExpiredConsumequeue=").append(cleanExpiredConsumequeue);
if (!getConsumerRunningInfo)
builder.append(", cleanUnusedTopic=").append(getConsumerRunningInfo);
if (!getConsumerRunningInfo)
builder.append(", getConsumerRunningInfo=").append(getConsumerRunningInfo);
if (!queryCorrectionOffset)
builder.append(", queryCorrectionOffset=").append(queryCorrectionOffset);
if (!consumeMessageDirectly)
builder.append(", consumeMessageDirectly=").append(consumeMessageDirectly);
if (!cloneGroupOffset)
builder.append(", cloneGroupOffset=").append(cloneGroupOffset);
if (!viewBrokerStatsData)
builder.append(", viewBrokerStatsData=").append(viewBrokerStatsData);
if (!getBrokerConsumeStats)
builder.append(", getBrokerConsumeStats=").append(getBrokerConsumeStats);
if (!queryConsumeQueue)
builder.append(", queryConsumeQueue=").append(queryConsumeQueue);
builder.append("]");
return builder.toString();
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
import java.util.List; import java.util.List;
...@@ -8,8 +24,6 @@ public class BorkerAccessControlTransport { ...@@ -8,8 +24,6 @@ public class BorkerAccessControlTransport {
private List<BorkerAccessControl> list; private List<BorkerAccessControl> list;
public BorkerAccessControlTransport() { public BorkerAccessControlTransport() {
super(); super();
} }
...@@ -35,6 +49,4 @@ public class BorkerAccessControlTransport { ...@@ -35,6 +49,4 @@ public class BorkerAccessControlTransport {
return "BorkerAccessControlTransport [onlyNetAddress=" + onlyNetAddress + ", list=" + list + "]"; return "BorkerAccessControlTransport [onlyNetAddress=" + onlyNetAddress + ", list=" + list + "]";
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class ControllerParametersEntity { public class ControllerParametersEntity {
private String fileHome;
public String getFileHome() {
return fileHome;
}
public void setFileHome(String fileHome) {
this.fileHome = fileHome;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ControllerParametersEntity [fileHome=").append(fileHome).append("]");
return builder.toString();
}
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.entity; package org.apache.rocketmq.acl.plug.entity;
public class LoginInfo { import java.util.concurrent.atomic.AtomicBoolean;
public class LoginInfo {
private String recognition; private String recognition;
private long loginTime = System.currentTimeMillis(); private long loginTime = System.currentTimeMillis();
private long operationTime = loginTime; private volatile long operationTime = loginTime;
private AuthenticationInfo authenticationInfo;
private volatile AtomicBoolean clear = new AtomicBoolean();
private AuthenticationInfo authenticationInfo;
public AuthenticationInfo getAuthenticationInfo() { public AuthenticationInfo getAuthenticationInfo() {
return authenticationInfo; return authenticationInfo;
...@@ -45,11 +62,21 @@ public class LoginInfo { ...@@ -45,11 +62,21 @@ public class LoginInfo {
this.operationTime = operationTime; this.operationTime = operationTime;
} }
public AtomicBoolean getClear() {
return clear;
}
public void setClear(AtomicBoolean clear) {
this.clear = clear;
}
@Override @Override
public String toString() { public String toString() {
return "LoginInfo [recognition=" + recognition + ", loginTime=" + loginTime + ", operationTime=" + operationTime StringBuilder builder = new StringBuilder();
+ ", authenticationInfo=" + authenticationInfo + "]"; builder.append("LoginInfo [recognition=").append(recognition).append(", loginTime=").append(loginTime)
.append(", operationTime=").append(operationTime).append(", clear=").append(clear)
.append(", authenticationInfo=").append(authenticationInfo).append("]");
return builder.toString();
} }
} }
package org.apache.rocketmq.acl.plug.entity; /*
* Licensed to the Apache Software Foundation (ASF) under one or more
/** * contributor license agreements. See the NOTICE file distributed with
* @author Administrator * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
public class LoginOrRequestAccessControl extends AccessControl { package org.apache.rocketmq.acl.plug.entity;
public class LoginOrRequestAccessControl extends AccessControl {
private int code; private int code;
...@@ -34,6 +45,4 @@ public class LoginOrRequestAccessControl extends AccessControl { ...@@ -34,6 +45,4 @@ public class LoginOrRequestAccessControl extends AccessControl {
return builder.toString(); return builder.toString();
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugAccountAnalysisException extends AclPlugRuntimeException {
private static final long serialVersionUID = -7286948517911075176L;
public AclPlugAccountAnalysisException(String message) {
super(message);
}
public AclPlugAccountAnalysisException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugAuthenticationException extends AclPlugRuntimeException {
private static final long serialVersionUID = 6365666045084521516L;
public AclPlugAuthenticationException(String message) {
super(message);
}
public AclPlugAuthenticationException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugException extends Exception {
private static final long serialVersionUID = 6843154847463800519L;
public AclPlugException(String message) {
super(message);
}
public AclPlugException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugLoginException extends AclPlugRuntimeException {
private static final long serialVersionUID = 4593661700080106122L;
public AclPlugLoginException(String message) {
super(message);
}
public AclPlugLoginException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugRuntimeException extends RuntimeException {
private static final long serialVersionUID = 6062101368637228900L;
public AclPlugRuntimeException(String message) {
super(message);
}
public AclPlugRuntimeException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.exception;
public class AclPlugStartException extends AclPlugException {
private static final long serialVersionUID = 5118936374739373693L;
public AclPlugStartException(String message) {
super(message);
}
public AclPlugStartException(String message, Throwable cause) {
super(message, cause);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.AclUtils; import org.apache.rocketmq.acl.plug.AclUtils;
public abstract class AbstractNetaddressStrategy implements NetaddressStrategy { public abstract class AbstractNetaddressStrategy implements NetaddressStrategy {
public void verify(String netaddress , int index) { public void verify(String netaddress, int index) {
AclUtils.isScope(netaddress, index); AclUtils.isScope(netaddress, index);
} }
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import java.util.HashSet; import java.util.HashSet;
...@@ -10,13 +26,12 @@ public class MultipleNetaddressStrategy extends AbstractNetaddressStrategy { ...@@ -10,13 +26,12 @@ public class MultipleNetaddressStrategy extends AbstractNetaddressStrategy {
private final Set<String> multipleSet = new HashSet<>(); private final Set<String> multipleSet = new HashSet<>();
public MultipleNetaddressStrategy(String[] strArray) { public MultipleNetaddressStrategy(String[] strArray) {
for(String netaddress : strArray) { for (String netaddress : strArray) {
verify(netaddress, 4); verify(netaddress, 4);
multipleSet.add(netaddress); multipleSet.add(netaddress);
} }
} }
@Override @Override
public boolean match(AccessControl accessControl) { public boolean match(AccessControl accessControl) {
return multipleSet.contains(accessControl.getNetaddress()); return multipleSet.contains(accessControl.getNetaddress());
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
public interface NetaddressStrategy { public interface NetaddressStrategy {
public boolean match(AccessControl accessControl); public boolean match(AccessControl accessControl);
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -6,23 +22,21 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl; ...@@ -6,23 +22,21 @@ import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class NetaddressStrategyFactory { public class NetaddressStrategyFactory {
public NetaddressStrategy getNetaddressStrategy(AccessControl accessControl) {
public NetaddressStrategy getNetaddressStrategy(AccessControl accessControl ) {
String netaddress = accessControl.getNetaddress(); String netaddress = accessControl.getNetaddress();
if(StringUtils.isBlank(netaddress) || "*".equals(netaddress) ) {//* if (StringUtils.isBlank(netaddress) || "*".equals(netaddress)) {
return NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY; return NullNetaddressStrategy.NULL_NET_ADDRESS_STRATEGY;
} }
if(netaddress.endsWith("}")) {//1.1.1.{1,2,3,4,5} if (netaddress.endsWith("}")) {
String[] strArray = StringUtils.split(netaddress); String[] strArray = StringUtils.split(netaddress);
String four = strArray[3]; String four = strArray[3];
if(!four.startsWith("{")) { if (!four.startsWith("{")) {
} }
return new MultipleNetaddressStrategy(AclUtils.getAddreeStrArray(netaddress, four)); return new MultipleNetaddressStrategy(AclUtils.getAddreeStrArray(netaddress, four));
}else if(AclUtils.isColon(netaddress)) {//1.1.1.1,1.2.3.4.5 } else if (AclUtils.isColon(netaddress)) {
return new MultipleNetaddressStrategy( StringUtils.split(",")); return new MultipleNetaddressStrategy(StringUtils.split(","));
}else if(AclUtils.isAsterisk(netaddress) || AclUtils.isMinus(netaddress)) {//1.2.*.* , 1.1.1.1-5 ,1.1.1-5.* } else if (AclUtils.isAsterisk(netaddress) || AclUtils.isMinus(netaddress)) {
return new RangeNetaddressStrategy(netaddress); return new RangeNetaddressStrategy(netaddress);
} }
return new OneNetaddressStrategy(netaddress); return new OneNetaddressStrategy(netaddress);
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
...@@ -6,7 +22,6 @@ public class NullNetaddressStrategy implements NetaddressStrategy { ...@@ -6,7 +22,6 @@ public class NullNetaddressStrategy implements NetaddressStrategy {
public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy(); public static final NullNetaddressStrategy NULL_NET_ADDRESS_STRATEGY = new NullNetaddressStrategy();
@Override @Override
public boolean match(AccessControl accessControl) { public boolean match(AccessControl accessControl) {
return true; return true;
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.rocketmq.acl.plug.entity.AccessControl; import org.apache.rocketmq.acl.plug.entity.AccessControl;
public class OneNetaddressStrategy extends AbstractNetaddressStrategy { public class OneNetaddressStrategy extends AbstractNetaddressStrategy {
private String netaddress; private String netaddress;
public OneNetaddressStrategy(String netaddress) { public OneNetaddressStrategy(String netaddress) {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.acl.plug.strategy; package org.apache.rocketmq.acl.plug.strategy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -15,51 +31,50 @@ public class RangeNetaddressStrategy extends AbstractNetaddressStrategy { ...@@ -15,51 +31,50 @@ public class RangeNetaddressStrategy extends AbstractNetaddressStrategy {
private int index; private int index;
public RangeNetaddressStrategy(String netaddress) { public RangeNetaddressStrategy(String netaddress) {
String[] strArray = StringUtils.split(netaddress , "."); String[] strArray = StringUtils.split(netaddress, ".");
if( analysis(strArray , 2) ||analysis(strArray , 3) ) { if (analysis(strArray, 2) || analysis(strArray, 3)) {
verify(netaddress, index); verify(netaddress, index);
StringBuffer sb = new StringBuffer().append( strArray[0].trim()).append(".").append( strArray[1].trim()).append("."); StringBuffer sb = new StringBuffer().append(strArray[0].trim()).append(".").append(strArray[1].trim()).append(".");
if(index == 3) { if (index == 3) {
sb.append( strArray[2].trim()).append("."); sb.append(strArray[2].trim()).append(".");
} }
this.head = sb.toString(); this.head = sb.toString();
} }
} }
private boolean analysis(String[] strArray , int index ) { private boolean analysis(String[] strArray, int index) {
String value = strArray[index].trim(); String value = strArray[index].trim();
this.index = index; this.index = index;
if( "*".equals( value) ){ if ("*".equals(value)) {
setValue(0, 255); setValue(0, 255);
}else if(AclUtils.isMinus( value )) { } else if (AclUtils.isMinus(value)) {
String[] valueArray = StringUtils.split( value , "-" ); String[] valueArray = StringUtils.split(value, "-");
this.start = Integer.valueOf(valueArray[0]); this.start = Integer.valueOf(valueArray[0]);
this.end = Integer.valueOf(valueArray[1]); this.end = Integer.valueOf(valueArray[1]);
if ( !(AclUtils.isScope( end ) && AclUtils.isScope( start ) && start <= end)) { if (!(AclUtils.isScope(end) && AclUtils.isScope(start) && start <= end)) {
} }
} }
return this.end > 0 ? true : false; return this.end > 0 ? true : false;
} }
private void setValue(int start, int end) {
private void setValue(int start , int end) { this.start = start;
this.start = start ;
this.end = end; this.end = end;
} }
@Override @Override
public boolean match(AccessControl accessControl) { public boolean match(AccessControl accessControl) {
String netAddress = accessControl.getNetaddress(); String netAddress = accessControl.getNetaddress();
if ( netAddress.startsWith(this.head)) { if (netAddress.startsWith(this.head)) {
String value; String value;
if(index == 3) { if (index == 3) {
value = netAddress.substring(this.head.length()); value = netAddress.substring(this.head.length());
}else { } else {
value = netAddress.substring(this.head.length() , netAddress.lastIndexOf('.')); value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
} }
Integer address = Integer.valueOf(value); Integer address = Integer.valueOf(value);
if( address>= this.start && address <= this.end ) { if (address >= this.start && address <= this.end) {
return true; return true;
} }
} }
......
...@@ -6,7 +6,7 @@ public class PlainAclPlugEngineTest { ...@@ -6,7 +6,7 @@ public class PlainAclPlugEngineTest {
@Test @Test
public void testPlainAclPlugEngineInit() { public void testPlainAclPlugEngineInit() {
PlainAclPlugEngine plainAclPlugEngine = new PlainAclPlugEngine(); //PlainAclPlugEngine plainAclPlugEngine = new PlainAclPlugEngine();
plainAclPlugEngine.init(); //plainAclPlugEngine.init();
} }
} }
...@@ -4,13 +4,13 @@ onlyNetAddress: ...@@ -4,13 +4,13 @@ onlyNetAddress:
- broker-a - broker-a
list: list:
- account: laohu - account: laohu
password: 123456 password: 123456
netaddress: 192.0.0.* netaddress: 192.0.0.*
permitSendTopic: permitSendTopic:
- test1 - test1
- test2 - test2
- account: laohu - account: laohu
password: 123456 password: 123456
netaddress: 192.0.2.1 netaddress: 192.0.2.1
permitSendTopic: permitSendTopic:
......
onlyNetAddress:
netaddress: 10.10.103.*
noPermitPullTopic:
- broker-a
list:
- account: laohu
password: 123456
netaddress: 192.0.0.*
permitSendTopic:
- test1
- test2
- account: laohu
password: 123456
netaddress: 192.0.2.1
permitSendTopic:
- test3
- test4
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册