Configure Maven repository for unionflow-server-api dependency
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
package dev.lions.unionflow.client.security;
|
||||
|
||||
import dev.lions.unionflow.client.view.UserSession;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Named("permissionChecker")
|
||||
@RequestScoped
|
||||
public class PermissionChecker implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Inject
|
||||
private UserSession userSession;
|
||||
|
||||
// Vérifications basées sur le rôle utilisateur
|
||||
public boolean hasRole(String role) {
|
||||
if (userSession == null || !userSession.isAuthenticated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String userRole = userSession.getRole();
|
||||
return role.equals(userRole);
|
||||
}
|
||||
|
||||
public boolean hasAnyRole(String... roles) {
|
||||
if (userSession == null || !userSession.isAuthenticated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String userRole = userSession.getRole();
|
||||
for (String role : roles) {
|
||||
if (role.equals(userRole)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérifications basées sur les permissions
|
||||
public boolean canManageMembers() {
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_MEMBRE");
|
||||
}
|
||||
|
||||
public boolean canValidateMembers() {
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_MEMBRE");
|
||||
}
|
||||
|
||||
public boolean canManageFinances() {
|
||||
return hasAnyRole("ADMIN", "TRESORIER", "GESTIONNAIRE_FINANCE");
|
||||
}
|
||||
|
||||
public boolean canManageEvents() {
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_EVENEMENT");
|
||||
}
|
||||
|
||||
public boolean canManageAides() {
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_AIDE");
|
||||
}
|
||||
|
||||
public boolean canViewReports() {
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_MEMBRE", "TRESORIER");
|
||||
}
|
||||
|
||||
public boolean canManageSubscription() {
|
||||
return hasRole("ADMIN");
|
||||
}
|
||||
|
||||
public boolean canManageOrganization() {
|
||||
return hasRole("ADMIN");
|
||||
}
|
||||
|
||||
public boolean canAccessSuperAdmin() {
|
||||
return hasRole("SUPER_ADMIN");
|
||||
}
|
||||
|
||||
// Vérifications basées sur les fonctionnalités du forfait
|
||||
public boolean isFeatureEnabled(String feature) {
|
||||
// Cette méthode vérifiera si la fonctionnalité est incluse dans le forfait souscrit
|
||||
// Pour l'instant, simulation basée sur des rôles
|
||||
|
||||
switch (feature.toLowerCase()) {
|
||||
case "gestion_membres":
|
||||
return true; // Toujours disponible
|
||||
|
||||
case "gestion_cotisations":
|
||||
return true; // Toujours disponible
|
||||
|
||||
case "gestion_evenements":
|
||||
return !hasRole("MEMBER"); // Pas pour les membres simples
|
||||
|
||||
case "gestion_aides":
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_AIDE");
|
||||
|
||||
case "rapports_avances":
|
||||
return hasAnyRole("ADMIN", "SUPER_ADMIN");
|
||||
|
||||
case "integration_paiement":
|
||||
return hasAnyRole("ADMIN", "TRESORIER");
|
||||
|
||||
case "notifications_sms":
|
||||
return hasAnyRole("ADMIN", "SUPER_ADMIN");
|
||||
|
||||
case "gestion_documents":
|
||||
return hasAnyRole("ADMIN", "GESTIONNAIRE_MEMBRE");
|
||||
|
||||
case "support_prioritaire":
|
||||
return hasAnyRole("ADMIN", "SUPER_ADMIN");
|
||||
|
||||
case "personnalisation_avancee":
|
||||
return hasRole("SUPER_ADMIN");
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Vérifications pour l'interface utilisateur
|
||||
public boolean showCreateMemberButton() {
|
||||
return canManageMembers() && isFeatureEnabled("gestion_membres");
|
||||
}
|
||||
|
||||
public boolean showValidateMemberButton() {
|
||||
return canValidateMembers() && isFeatureEnabled("gestion_membres");
|
||||
}
|
||||
|
||||
public boolean showFinancialSection() {
|
||||
return canManageFinances() && isFeatureEnabled("gestion_cotisations");
|
||||
}
|
||||
|
||||
public boolean showEventsSection() {
|
||||
return canManageEvents() && isFeatureEnabled("gestion_evenements");
|
||||
}
|
||||
|
||||
public boolean showAidesSection() {
|
||||
return canManageAides() && isFeatureEnabled("gestion_aides");
|
||||
}
|
||||
|
||||
public boolean showReportsSection() {
|
||||
return canViewReports() && isFeatureEnabled("rapports_avances");
|
||||
}
|
||||
|
||||
public boolean showSubscriptionManagement() {
|
||||
return canManageSubscription();
|
||||
}
|
||||
|
||||
public boolean showAdvancedSettings() {
|
||||
return canManageOrganization() && isFeatureEnabled("personnalisation_avancee");
|
||||
}
|
||||
|
||||
public boolean showSuperAdminFeatures() {
|
||||
return canAccessSuperAdmin();
|
||||
}
|
||||
|
||||
// Vérifications spécifiques aux actions
|
||||
public boolean canCreateEvent() {
|
||||
return canManageEvents() && isFeatureEnabled("gestion_evenements");
|
||||
}
|
||||
|
||||
public boolean canProcessAideRequest() {
|
||||
return canManageAides() && isFeatureEnabled("gestion_aides");
|
||||
}
|
||||
|
||||
public boolean canExportData() {
|
||||
return canViewReports() && isFeatureEnabled("rapports_avances");
|
||||
}
|
||||
|
||||
public boolean canSendNotifications() {
|
||||
return canManageMembers() && (isFeatureEnabled("notifications_email") || isFeatureEnabled("notifications_sms"));
|
||||
}
|
||||
|
||||
public boolean canManageDocuments() {
|
||||
return canManageMembers() && isFeatureEnabled("gestion_documents");
|
||||
}
|
||||
|
||||
// Vérifications pour les limites
|
||||
public boolean canAddNewMember() {
|
||||
if (!canManageMembers()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérifier le quota de membres (sera implémenté avec SouscriptionBean)
|
||||
// Pour l'instant, toujours vrai si on a les permissions
|
||||
return true;
|
||||
}
|
||||
|
||||
// Méthodes utilitaires pour l'affichage conditionnel
|
||||
public String getRoleBasedStyleClass() {
|
||||
if (!userSession.isAuthenticated()) {
|
||||
return "guest-mode";
|
||||
}
|
||||
|
||||
String role = userSession.getRole();
|
||||
switch (role) {
|
||||
case "SUPER_ADMIN":
|
||||
return "super-admin-mode";
|
||||
case "ADMIN":
|
||||
return "admin-mode";
|
||||
case "GESTIONNAIRE_MEMBRE":
|
||||
return "gestionnaire-mode";
|
||||
case "TRESORIER":
|
||||
return "tresorier-mode";
|
||||
case "MEMBER":
|
||||
default:
|
||||
return "member-mode";
|
||||
}
|
||||
}
|
||||
|
||||
public String getPermissionMessage(String action) {
|
||||
return "Vous n'avez pas les permissions nécessaires pour " + action;
|
||||
}
|
||||
|
||||
// Getters pour utilisation dans les expressions EL
|
||||
public boolean isAuthenticated() {
|
||||
return userSession != null && userSession.isAuthenticated();
|
||||
}
|
||||
|
||||
public boolean isSuperAdmin() {
|
||||
return hasRole("SUPER_ADMIN");
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return hasRole("ADMIN");
|
||||
}
|
||||
|
||||
public boolean isMember() {
|
||||
return hasRole("MEMBER");
|
||||
}
|
||||
|
||||
public boolean isGestionnaire() {
|
||||
return hasAnyRole("GESTIONNAIRE_MEMBRE", "GESTIONNAIRE_EVENEMENT", "GESTIONNAIRE_AIDE", "GESTIONNAIRE_FINANCE");
|
||||
}
|
||||
|
||||
public boolean isTresorier() {
|
||||
return hasRole("TRESORIER");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user