Search in sources :

Example 1 with PersonaUserSession

use of io.vertigo.persona.security.PersonaUserSession in project vertigo by KleeGroup.

the class VSecurityManagerImpl method isAuthorized.

/**
 * {@inheritDoc}
 */
@Override
public boolean isAuthorized(final String resource, final String operation) {
    // Note: il s'agit d'une implementation naïve non optimisee,
    // réalisée pour valider le modèle
    final Optional<PersonaUserSession> userSessionOption = getCurrentUserSession();
    if (!userSessionOption.isPresent()) {
        // Si il n'y a pas de session alors pas d'autorisation.
        return false;
    }
    final PersonaUserSession userSession = userSessionOption.get();
    final Map<String, String> securityKeys = userSessionOption.get().getSecurityKeys();
    return userSession.getRoles().stream().anyMatch(role -> isAuthorized(role, resource, operation, securityKeys));
}
Also used : PersonaUserSession(io.vertigo.persona.security.PersonaUserSession)

Example 2 with PersonaUserSession

use of io.vertigo.persona.security.PersonaUserSession in project vertigo by KleeGroup.

the class VSecurityManagerImpl method hasRole.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasRole(final Set<Role> authorizedRoleSet) {
    Assertion.checkNotNull(authorizedRoleSet);
    // -----
    if (authorizedRoleSet.isEmpty()) {
        return true;
    }
    // Si il existe au moins un role parmi la liste des roles autorises
    // il faut alors regarder si l'utilisateur possede un role de la liste.
    final Optional<PersonaUserSession> userSessionOpt = getCurrentUserSession();
    Assertion.checkState(userSessionOpt.isPresent(), "User not logged");
    final Set<Role> userProfiles = userSessionOpt.get().getRoles();
    for (final Role role : authorizedRoleSet) {
        Assertion.checkArgument(Home.getApp().getDefinitionSpace().contains(role.getName()), "Le role {0} n est pas defini dans RoleRegistry.", role);
        if (userProfiles.contains(role)) {
            return true;
        }
    }
    // Si on a trouve aucun des roles autorises alors l'acces est interdit
    return false;
}
Also used : Role(io.vertigo.persona.security.metamodel.Role) PersonaUserSession(io.vertigo.persona.security.PersonaUserSession)

Aggregations

PersonaUserSession (io.vertigo.persona.security.PersonaUserSession)2 Role (io.vertigo.persona.security.metamodel.Role)1