All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.uid2.shared.auth.RoleBasedAuthorizationProvider Maven / Gradle / Ivy

package com.uid2.shared.auth;

import java.util.Set;

public class RoleBasedAuthorizationProvider implements IAuthorizationProvider {
    private final Set allowedRoles;

    public RoleBasedAuthorizationProvider(Set allowedRoles) {
        this.allowedRoles = allowedRoles;
    }

    @Override
    public boolean isAuthorized(IAuthorizable client) {
        if (client == null || client.isDisabled()) {
            return false;
        }

        try {
            final IRoleAuthorizable profile = (IRoleAuthorizable) client;
            return this.allowedRoles.stream().anyMatch(profile::hasRole);
        } catch (Exception ex) {
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy