2 Replies Latest reply on May 14, 2009 4:50 PM by aalves

    Authorization check failed for expression

    aalves

      Hi,
      I want to restrict some functions to one role or more than one, the problem is that it does not work whe I write it like this:


      @Restrict("#{s:hasRole('admin')} or s:hasRole('operador')}")




      Do you know what might be wrong.
      Regards

        • 1. Re: Authorization check failed for expression
          gus888

          It should be:

          @Restrict("#{s:hasRole('admin') or s:hasRole('operador')}")

          • 2. Re: Authorization check failed for expression
            aalves

            Hi,
            I noticed the mistake, but it still doesn´t work.
            I wrote a log in the jps to see if I have the role and it says that I do, but then when I enter on the method it says that I do not have it.
            Do I have to inject anything? it was working before. This is the code of my backing object:




            @Name("crearActividadAction")
            @Scope(ScopeType.PAGE)
            public class CrearActividadAction
            {
                @Logger private Log log;
            
                @In StatusMessages statusMessages;
            
                private Integer numeroCampos;
                  
                 private String nombre;
                
                private String descripcion;
                
                private List<Campo> tiposCampoSeleccionados;
            
                private List<Tipocampo> tiposCampos;
            
                public CrearActividadAction()
                {
                     tiposCampoSeleccionados=new ArrayList<Campo>();
                }
            
                @Restrict("#{s:hasRole('admin') or s:hasRole('operador')}")
                public String salvar()
                {
                     ActividadService actividadService = new ActividadService();
                     UsuarioService usuarioService = new  UsuarioService();
                     CampoService campoService = new CampoService();
                     Actividad actividad = new Actividad();
                     actividad.setNombre(nombre);
                     actividad.setDescripcion(descripcion);
                      Usuario usuario = (Usuario)Contexts.getSessionContext().get("usuario");
                     actividad.setLugar(usuario.getLugar());
                     actividadService.save(actividad);
                     
                     for(Campo campo : tiposCampoSeleccionados)
                     {
                          campo.setActividad(actividad);
                          campoService.save(campo);
                     }
                     
                     Contexts.getSessionContext().set("idActividad", actividad.getId());
                     
                     return "success";
                }
              
                public List<Tipocampo>  getTiposCampos()
                {
                     return new TipocampoList().getResultList();     
                }
            
                
                public void setTiposCampos(List<Tipocampo>  campos)
                {
                     this.tiposCampos=campos;
                }
                
                
                public void setTiposCamposSeleccionados(List<Campo> seleccionados)
                {
                     this.tiposCampoSeleccionados=seleccionados;
                }
                
                public List<Campo> getTiposCamposSeleccionados()
                {
                     return this.tiposCampoSeleccionados;
                }  
                
                public String getNombre() {
                      return nombre;
                 }
            
                 public void setNombre(String nombre) {
                      this.nombre = nombre;
                 }
            
                 public String getDescripcion() {
                      return descripcion;
                 }
            
                 public void setDescripcion(String descripcion) {
                      this.descripcion = descripcion;
                 }
                     
                public Integer getNumeroCampos() {
                      return numeroCampos;
                 }
            
                 public void setNumeroCampos(Integer numeroCampos) {
                      this.numeroCampos = numeroCampos;
                 }
            
                 public void addCampo()
                 {
                      tiposCampoSeleccionados.add(new Campo());
                      System.out.print("hola");
                 }
                 
                 public void deleteCampo(int i)
                 {
                      tiposCampoSeleccionados.remove(i);
                 }
            }