| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | | -import javax.annotation.security.RolesAllowed; |
|---|
| 3 | +import javax.inject.Inject; |
|---|
| 4 | 4 | import javax.servlet.http.HttpServletRequest; |
|---|
| 5 | 5 | import javax.ws.rs.FormParam; |
|---|
| 6 | 6 | import javax.ws.rs.GET; |
|---|
| .. | .. |
|---|
| 14 | 14 | import javax.ws.rs.core.Response.Status; |
|---|
| 15 | 15 | |
|---|
| 16 | 16 | import net.curisit.integrity.commons.Utils; |
|---|
| 17 | +import net.curisit.securis.utils.TokenHelper; |
|---|
| 17 | 18 | |
|---|
| 18 | 19 | import org.slf4j.Logger; |
|---|
| 19 | 20 | import org.slf4j.LoggerFactory; |
|---|
| .. | .. |
|---|
| 25 | 26 | */ |
|---|
| 26 | 27 | @Path("/user") |
|---|
| 27 | 28 | public class UserResource { |
|---|
| 29 | + |
|---|
| 30 | + @Inject |
|---|
| 31 | + TokenHelper tokenHelper; |
|---|
| 28 | 32 | |
|---|
| 29 | 33 | // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class); |
|---|
| 30 | 34 | private static final Logger log = LoggerFactory.getLogger(UserResource.class); |
|---|
| .. | .. |
|---|
| 56 | 60 | request.getSession().setAttribute("username", user); |
|---|
| 57 | 61 | if ("no".equals(password)) |
|---|
| 58 | 62 | return Response.status(Status.FORBIDDEN).build(); |
|---|
| 59 | | - return Response.ok(Utils.createMap("name", "Pepito", "username", user)).build(); |
|---|
| 63 | + String tokenAuth = tokenHelper.generateToken(user); |
|---|
| 64 | + return Response.ok(Utils.createMap("success", true, "token", tokenAuth)).build(); |
|---|
| 60 | 65 | } |
|---|
| 61 | 66 | |
|---|
| 62 | 67 | /** |
|---|
| .. | .. |
|---|
| 66 | 71 | @Path("/{username}") |
|---|
| 67 | 72 | @Produces( |
|---|
| 68 | 73 | { MediaType.APPLICATION_JSON }) |
|---|
| 69 | | - @RolesAllowed("advance") |
|---|
| 74 | + // @RolesAllowed("advance") |
|---|
| 70 | 75 | public Response main(@PathParam("username") String username) { |
|---|
| 71 | 76 | return Response.ok().entity(Utils.createMap("name", "Pepito", "username", username)).build(); |
|---|
| 72 | 77 | } |
|---|