Question

I'm a totally beginner in JEE 7. i'm trying to implement a secured model for an enterprise application using (Primefaces 4.0 and Glassfish 4.0 )but when I call ejb' secured methods using annotations from managed bean it doesn't check for the security on the method. I want to create the security in both levels(web and ejb): the first part on the web I have implemented but the other part is for the ejb methods is my problem. any help ??

this is the managed bean (buttonControlles.java)

@Named
@RequestScoped

 public class buttonController {  

    mySec myClass;

    public buttonController(){
     myClass = new mySec();
    }

    public void adminMethod()
    {
        if(myClass.ifManager())
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Hello Manager", "")); 
    }
}

and the ejb class is MySec.java

@DeclareRoles({"admin","users","manager"})

@Stateless public class mySec {

    @RolesAllowed("manager")
    public boolean ifManager()
    {
        return true;
    }
}
Était-ce utile?

La solution

I have solved the problem it was because i instantiated the class MySec.java it have to be injected in the managed bean not instantiated

@Named
@RequestScoped

public class buttonController {  

@EJB mySec myClass;

public buttonController(){
}

public void adminMethod()
{
    if(myClass.ifManager())
        FacesContext.getCurrentInstance().addMessage(null, new  FacesMessage(FacesMessage.SEVERITY_INFO,"Hello Manager", "")); 
}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top