com.gateway.invoke.security.LimitSecurityCheck Maven / Gradle / Ivy
package com.gateway.invoke.security;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.gateway.connector.Session;
import com.gateway.connector.proto.Proto;
import com.gateway.connector.tcp.TcpSessionManager;
import com.gateway.message.SystemMessage;
public class LimitSecurityCheck implements ISecurityCheck {
private static int LimitCheck = 10003;
private static String LimitCheckMsg = "%s";
private int limitQps = 100;
private TcpSessionManager tcpSessionManager;
public void setTcpSessionManager(TcpSessionManager tcpSessionManager) {
this.tcpSessionManager = tcpSessionManager;
}
public int getLimitQps() {
return limitQps;
}
public void setLimitQps(int limitQps) {
this.limitQps = limitQps;
}
public void init() {
}
@Override
public SecurityResult check(SystemMessage sMsg, Proto message, String serverName, String method, String content,Map, ?> hm ) {
SecurityResult pr = new SecurityResult();
if (StringUtils.isNoneBlank(message.getSessionId())) {//
Session session = tcpSessionManager.getSession(message.getSessionId());
if (session != null) {
String userName = session.getUserName() + "";
boolean flag = LimitApi.LimitCheck(userName, limitQps);
if (!flag) {
pr.code = LimitCheck;
pr.msg = String.format(LimitCheckMsg, userName);
}
}
}
return pr;
}
}