Commit 6c69f714c26543ddd298f5f1f6dcee86f0f6c30a
Exists in
master
Merge branch 'master' of https://github.com/demoiselle/framework.git
Showing
4 changed files
with
10 additions
and
18 deletions
Show diff stats
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionMapper.java
| @@ -41,7 +41,6 @@ import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; | @@ -41,7 +41,6 @@ import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; | ||
| 41 | 41 | ||
| 42 | import java.util.logging.Logger; | 42 | import java.util.logging.Logger; |
| 43 | 43 | ||
| 44 | -import javax.ws.rs.Produces; | ||
| 45 | import javax.ws.rs.core.Response; | 44 | import javax.ws.rs.core.Response; |
| 46 | import javax.ws.rs.ext.ExceptionMapper; | 45 | import javax.ws.rs.ext.ExceptionMapper; |
| 47 | import javax.ws.rs.ext.Provider; | 46 | import javax.ws.rs.ext.Provider; |
| @@ -59,14 +58,13 @@ public class AuthenticationExceptionMapper implements ExceptionMapper<Authentica | @@ -59,14 +58,13 @@ public class AuthenticationExceptionMapper implements ExceptionMapper<Authentica | ||
| 59 | private transient Logger logger; | 58 | private transient Logger logger; |
| 60 | 59 | ||
| 61 | @Override | 60 | @Override |
| 62 | - @Produces("text/plain") | ||
| 63 | public Response toResponse(AuthenticationException exception) { | 61 | public Response toResponse(AuthenticationException exception) { |
| 64 | int status = SC_UNAUTHORIZED; | 62 | int status = SC_UNAUTHORIZED; |
| 65 | 63 | ||
| 66 | String message = getBundle().getString("mapping-violations", status); | 64 | String message = getBundle().getString("mapping-violations", status); |
| 67 | getLogger().log(FINE, message, exception); | 65 | getLogger().log(FINE, message, exception); |
| 68 | 66 | ||
| 69 | - return Response.status(status).entity(exception.getMessage()).build(); | 67 | + return Response.status(status).entity(exception.getMessage()).type("text/plain").build(); |
| 70 | } | 68 | } |
| 71 | 69 | ||
| 72 | private ResourceBundle getBundle() { | 70 | private ResourceBundle getBundle() { |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionMapper.java
| @@ -41,7 +41,6 @@ import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; | @@ -41,7 +41,6 @@ import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; | ||
| 41 | 41 | ||
| 42 | import java.util.logging.Logger; | 42 | import java.util.logging.Logger; |
| 43 | 43 | ||
| 44 | -import javax.ws.rs.Produces; | ||
| 45 | import javax.ws.rs.core.Response; | 44 | import javax.ws.rs.core.Response; |
| 46 | import javax.ws.rs.ext.ExceptionMapper; | 45 | import javax.ws.rs.ext.ExceptionMapper; |
| 47 | import javax.ws.rs.ext.Provider; | 46 | import javax.ws.rs.ext.Provider; |
| @@ -59,14 +58,13 @@ public class AuthorizationExceptionMapper implements ExceptionMapper<Authorizati | @@ -59,14 +58,13 @@ public class AuthorizationExceptionMapper implements ExceptionMapper<Authorizati | ||
| 59 | private transient Logger logger; | 58 | private transient Logger logger; |
| 60 | 59 | ||
| 61 | @Override | 60 | @Override |
| 62 | - @Produces("text/plain") | ||
| 63 | public Response toResponse(AuthorizationException exception) { | 61 | public Response toResponse(AuthorizationException exception) { |
| 64 | int status = SC_FORBIDDEN; | 62 | int status = SC_FORBIDDEN; |
| 65 | 63 | ||
| 66 | String message = getBundle().getString("mapping-violations", status); | 64 | String message = getBundle().getString("mapping-violations", status); |
| 67 | getLogger().log(FINE, message, exception); | 65 | getLogger().log(FINE, message, exception); |
| 68 | 66 | ||
| 69 | - return Response.status(status).entity(exception.getMessage()).build(); | 67 | + return Response.status(status).entity(exception.getMessage()).type("text/plain").build(); |
| 70 | } | 68 | } |
| 71 | 69 | ||
| 72 | private ResourceBundle getBundle() { | 70 | private ResourceBundle getBundle() { |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/AbstractHTTPAuthorizationFilter.java
| @@ -157,17 +157,13 @@ public abstract class AbstractHTTPAuthorizationFilter implements Filter { | @@ -157,17 +157,13 @@ public abstract class AbstractHTTPAuthorizationFilter implements Filter { | ||
| 157 | 157 | ||
| 158 | private void setUnauthorizedStatus(HttpServletResponse response, AuthenticationException cause) throws IOException { | 158 | private void setUnauthorizedStatus(HttpServletResponse response, AuthenticationException cause) throws IOException { |
| 159 | response.setStatus(SC_UNAUTHORIZED); | 159 | response.setStatus(SC_UNAUTHORIZED); |
| 160 | - response.setContentType("text/plain; charset=UTF-8"); | ||
| 161 | - response.getWriter().write(cause.getMessage()); | ||
| 162 | - } | ||
| 163 | 160 | ||
| 164 | - // private ResourceBundle getBundle() { | ||
| 165 | - // if (bundle == null) { | ||
| 166 | - // bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-rest-bundle")); | ||
| 167 | - // } | ||
| 168 | - // | ||
| 169 | - // return bundle; | ||
| 170 | - // } | 161 | + String message = cause.getMessage(); |
| 162 | + if (!Strings.isEmpty(message)) { | ||
| 163 | + response.setContentType("text/plain; charset=UTF-8"); | ||
| 164 | + response.getWriter().write(message); | ||
| 165 | + } | ||
| 166 | + } | ||
| 171 | 167 | ||
| 172 | private Logger getLogger() { | 168 | private Logger getLogger() { |
| 173 | if (logger == null) { | 169 | if (logger == null) { |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthenticator.java
| @@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package br.gov.frameworkdemoiselle.security; | 37 | package br.gov.frameworkdemoiselle.security; |
| 38 | 38 | ||
| 39 | -import static br.gov.frameworkdemoiselle.annotation.Priority.L2_PRIORITY; | 39 | +import static br.gov.frameworkdemoiselle.annotation.Priority.L3_PRIORITY; |
| 40 | 40 | ||
| 41 | import java.security.Principal; | 41 | import java.security.Principal; |
| 42 | 42 | ||
| @@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.util.Beans; | @@ -47,7 +47,7 @@ import br.gov.frameworkdemoiselle.util.Beans; | ||
| 47 | import br.gov.frameworkdemoiselle.util.StrategyQualifier; | 47 | import br.gov.frameworkdemoiselle.util.StrategyQualifier; |
| 48 | 48 | ||
| 49 | @RequestScoped | 49 | @RequestScoped |
| 50 | -@Priority(L2_PRIORITY) | 50 | +@Priority(L3_PRIORITY) |
| 51 | public class TokenAuthenticator implements Authenticator { | 51 | public class TokenAuthenticator implements Authenticator { |
| 52 | 52 | ||
| 53 | private static final long serialVersionUID = 1L; | 53 | private static final long serialVersionUID = 1L; |