Search in sources :

Example 1 with IpMatcher

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"));
                }
            }
        }
    }
}
Also used : IpMatcher(com.haulmont.cuba.security.global.IpMatcher) UserIpRestrictedException(com.haulmont.cuba.security.global.UserIpRestrictedException) UserSession(com.haulmont.cuba.security.global.UserSession) AbstractClientCredentials(com.haulmont.cuba.security.auth.AbstractClientCredentials)

Aggregations

AbstractClientCredentials (com.haulmont.cuba.security.auth.AbstractClientCredentials)1 IpMatcher (com.haulmont.cuba.security.global.IpMatcher)1 UserIpRestrictedException (com.haulmont.cuba.security.global.UserIpRestrictedException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1