SHARE
TWEET

com.apuntesdejava.rest.seguridad.CalculadoraService

apuntesdejava Apr 16th, 2013 6,817 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.apuntesdejava.rest.seguridad;
  2.  
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. import javax.annotation.security.DeclareRoles;
  6. import javax.annotation.security.RolesAllowed;
  7. import javax.ejb.Stateless;
  8. import javax.ws.rs.GET;
  9. import javax.ws.rs.Path;
  10. import javax.ws.rs.QueryParam;
  11.  
  12. @Stateless
  13. @Path("/calculadora")
  14. @DeclareRoles({"USER","ADMIN"})
  15. public class CalculadoraService {
  16.  
  17.     static final Logger LOGGER = Logger.getLogger(CalculadoraService.class.getName());
  18.  
  19.     @GET
  20.     @RolesAllowed("USER")
  21.     @Path("/factorial")
  22.     public String factorial(@QueryParam("base") long base) {
  23.         LOGGER.log(Level.INFO, "Realizando factorial({0})", base);
  24.         return String.valueOf(_factorial(base));
  25.     }
  26.  
  27.     private long _factorial(long base) {
  28.         LOGGER.log(Level.FINE, "factorial({0})", base);
  29.         if (base > 1) {
  30.             return base * _factorial(base - 1);
  31.         }
  32.         return 1;
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top