/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.Application;
import javax.faces.bean.ManagedBean;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
@DeclareRoles({"Chef","Normalo"})
public class Wahrheit {

  @RolesAllowed({"Chef","Normalo"})
  public String getWahr(){
    return "Der Kunde ist König";
  }

  @RolesAllowed("Chef")
  public String getEchtWahr(){
    FacesContext fctx = FacesContext.getCurrentInstance();
    ExternalContext ectx= fctx.getExternalContext();
    Application ap = fctx.getApplication();
    String tmp= ectx.getRemoteUser();
    String[] r={"Chef","Normalo"};
    for(String s:r)
      tmp+=" :"+ectx.isUserInRole(s);
    //ectx.invalidateSession();
    
    return "Der Kunde ist König der Ahnungslosen "+tmp;
  }

  public String getNanu(){
    return "Nanu";
  }

}
