1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
public class SessionBehavior extends LySessionBehavior
{
/**
* Validates the given action for the given controller.
*
* @param session the current session
* @param action the action to validate
* @param controller the controller for this action
* @return true if the action is valid, false otherwise.
* @see leon.app.behaviorinterface.LySessionBehaviorInterface#validateAction
*/
public boolean validateAction(LySession session, LyAction action, LyController controller)
{
int ROLE_COMMERCIAL_MARK = LyAction.getMark("ROLE_COMMERCIAL");
int ROLE_ADMIN = LyAction.getMark("ROLE_ADMIN");
if (action.hasMark(ROLE_COMMERCIAL_MARK))
{
// L'action a la marque spécifique ROLE_COMMERCIAL, autorisée si et seulement si l'utilisateur à le role commercial
LyObject user = session.getUser();
if (user == null)
return false;
LyObject role = user.getRelationValue("user_role").getObject(0);
if (role == null)
return false;
String roleName = role.getName();
if ((!"Commercial".equals(roleName)) && (!"Admin".equals(roleName)))
return false;
}
if (action.hasMark(ROLE_ADMIN))
{
// L'action a la marque spécifique ROLE_ADMIN, autorisée si et seulement si l'utilisateur à le role admin
LyObject user = session.getUser();
if (user == null)
return false;
LyObject role = user.getRelationValue("user_role").getObject(0);
if (role == null)
return false;
String roleName = role.getName();
if (!"Admin".equals(roleName))
return false;
}
return super.validateAction(session, action, controller);
}
public boolean enableAction(LySession session, LyAction action, LyController controller, LyObjectList objects, boolean showError) {
if (!validateAction(session, action, controller))
return false;
return super.enableAction(session, action, controller, objects, showError);
}
} |
Partager