use of com.haulmont.cuba.security.global.IpMatcher in project cuba by cuba-platform.
the class IpMaskUserAccessChecker method check.
@Override
public void check(Credentials credentials, AuthenticationDetails authenticationDetails) throws LoginException {
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
if (clientCredentials.isCheckClientPermissions() && clientCredentials.getIpAddress() != null) {
String ipAddress = clientCredentials.getIpAddress();
UserSession session = authenticationDetails.getSession();
if (session.getUser().getIpMask() != null) {
IpMatcher ipMatcher = new IpMatcher(session.getUser().getIpMask());
if (!ipMatcher.match(ipAddress)) {
log.info("IP address {} is not permitted for user {}", ipAddress, session.getUser());
throw new UserIpRestrictedException(messages.getMessage(MSG_PACK, "LoginException.invalidIP"));
}
}
}
}
}
Aggregations