
package de.ivu.elect.jee.security;

import java.util.List;

import javax.ejb.ApplicationException;

import de.ivu.elect.jee.exception.ElectCommonException;
import de.ivu.elect.jee.faces.Messages;

@ApplicationException(rollback = true)
public class SecurityException extends ElectCommonException {

  private static final long serialVersionUID = 1L;
  public static final String REQUIRED_PERMISSION_MISSING = "security.permission.missing";
  public static final String REQUIRED_VIEW_PERMISSION_MISSING = "security.permission.missing.for.view";
  private static final RedirectDestination DESTINATION = RedirectDestination.START_VIEW;

  public SecurityException(Messages messages, Permission requiredPermission, List< ? extends Permission> availablePermissions,
                           String className, String methodeName) {
    super(DESTINATION, LogLevel.MESSAGE_ONLY, REQUIRED_PERMISSION_MISSING, requiredPermission, requiredPermission.lokalisiere(messages), availablePermissions, className,
        methodeName, requiredPermission.getClass().getName());
  }

  public SecurityException(Messages messages, String viewid, Permission requiredPermission,
      List< ? extends Permission> availablePermissions) {
    super(DESTINATION, LogLevel.MESSAGE_ONLY, REQUIRED_VIEW_PERMISSION_MISSING, viewid, requiredPermission, requiredPermission.lokalisiere(messages), availablePermissions,
        requiredPermission.getClass().getName());
  }

  @Override
  public boolean isSecurityException() {
    return true;
  }
}
