|
@@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -72,6 +74,11 @@ abstract class BaseAction extends StandardJaxrsAction {
|
|
|
EffectivePerson effectivePerson = new EffectivePerson(person.getDistinguishedName(), tokenType,
|
|
EffectivePerson effectivePerson = new EffectivePerson(person.getDistinguishedName(), tokenType,
|
|
|
Config.token().getCipher());
|
|
Config.token().getCipher());
|
|
|
if ((null != request) && (null != response)) {
|
|
if ((null != request) && (null != response)) {
|
|
|
|
|
+ String clientIp = HttpToken.remoteAddress(request);
|
|
|
|
|
+ logger.debug("{} client ip is : {}",person.getDistinguishedName(), clientIp);
|
|
|
|
|
+ if(!this.checkIp(clientIp, person.getIpAddress())){
|
|
|
|
|
+ throw new ExceptionInvalidIpAddress(clientIp);
|
|
|
|
|
+ }
|
|
|
httpToken.setToken(request, response, effectivePerson);
|
|
httpToken.setToken(request, response, effectivePerson);
|
|
|
}
|
|
}
|
|
|
t.setToken(effectivePerson.getToken());
|
|
t.setToken(effectivePerson.getToken());
|
|
@@ -283,4 +290,25 @@ abstract class BaseAction extends StandardJaxrsAction {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected boolean checkIp(String clientIp, String ipAddress){
|
|
|
|
|
+ boolean returnValue = true;
|
|
|
|
|
+ if(StringUtils.isNotEmpty(clientIp) && StringUtils.isNotEmpty(ipAddress)){
|
|
|
|
|
+ try {
|
|
|
|
|
+ String[] ipAddressArr = StringUtils.split(ipAddress, ",");
|
|
|
|
|
+ for (String regIp : ipAddressArr) {
|
|
|
|
|
+ if(StringUtils.isNotEmpty(regIp)) {
|
|
|
|
|
+ Pattern pattern = Pattern.compile(regIp.trim());
|
|
|
|
|
+ Matcher matcher = pattern.matcher(clientIp);
|
|
|
|
|
+ returnValue = matcher.find();
|
|
|
|
|
+ if(returnValue){
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return returnValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|