Last change
on this file since 1489193 was
1489193,
checked in by antonioaraujob <aaraujo@…>, 9 years ago
|
Agregadas clases para realizar autenticación básica de HTTP en el servicio web. Mejoras en la documentación del API (apidoc). Ahora los recursos del servicio se consumen con autenticación básica HTTP y sobre HTTPS.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[1489193] | 1 | package ve.gob.cenditel.murachi; |
---|
| 2 | |
---|
| 3 | import javax.ws.rs.WebApplicationException; |
---|
| 4 | import javax.ws.rs.container.ContainerRequestContext; |
---|
| 5 | import javax.ws.rs.container.ContainerRequestFilter; |
---|
| 6 | import javax.ws.rs.core.Response; |
---|
| 7 | import javax.ws.rs.core.Response.Status; |
---|
| 8 | import javax.ws.rs.ext.Provider; |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * Filtro para realizar autenticación basica HTTP. |
---|
| 12 | * |
---|
| 13 | * @author aaraujo |
---|
| 14 | * |
---|
| 15 | */ |
---|
| 16 | @Provider |
---|
| 17 | @Authenticator |
---|
| 18 | public class JaxRsFilterAuthentication implements ContainerRequestFilter { |
---|
| 19 | public static final String AUTHENTICATION_HEADER = "Authorization"; |
---|
| 20 | |
---|
| 21 | @Override |
---|
| 22 | public void filter(ContainerRequestContext containerRequest) |
---|
| 23 | throws WebApplicationException { |
---|
| 24 | |
---|
| 25 | String authCredentials = containerRequest |
---|
| 26 | .getHeaderString(AUTHENTICATION_HEADER); |
---|
| 27 | |
---|
| 28 | // better injected |
---|
| 29 | AuthenticationService authenticationService = new AuthenticationService(); |
---|
| 30 | |
---|
| 31 | boolean authenticationStatus = authenticationService |
---|
| 32 | .authenticate(authCredentials); |
---|
| 33 | |
---|
| 34 | if (!authenticationStatus) { |
---|
| 35 | //throw new WebApplicationException(Status.UNAUTHORIZED); |
---|
| 36 | |
---|
| 37 | String errorMessage = "{\"error\":\"acceso no autorizado\"}"; |
---|
| 38 | Response response = Response.status(Status.UNAUTHORIZED).entity(errorMessage).build(); |
---|
| 39 | |
---|
| 40 | throw new WebApplicationException(response); |
---|
| 41 | |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | } |
---|
| 45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.