Commit 54eb45fc793ef1b2526e8dd23bf8af970af60633
1 parent
d247e661
Exists in
master
FWK-235: HTTP 401 retorna conteúdo incompatível com o cabeçalho
Task-Url: https://demoiselle.atlassian.net/browse/FWK-235
Showing
3 changed files
with
8 additions
and
16 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 | 41 | |
| 42 | 42 | import java.util.logging.Logger; |
| 43 | 43 | |
| 44 | -import javax.ws.rs.Produces; | |
| 45 | 44 | import javax.ws.rs.core.Response; |
| 46 | 45 | import javax.ws.rs.ext.ExceptionMapper; |
| 47 | 46 | import javax.ws.rs.ext.Provider; |
| ... | ... | @@ -59,14 +58,13 @@ public class AuthenticationExceptionMapper implements ExceptionMapper<Authentica |
| 59 | 58 | private transient Logger logger; |
| 60 | 59 | |
| 61 | 60 | @Override |
| 62 | - @Produces("text/plain") | |
| 63 | 61 | public Response toResponse(AuthenticationException exception) { |
| 64 | 62 | int status = SC_UNAUTHORIZED; |
| 65 | 63 | |
| 66 | 64 | String message = getBundle().getString("mapping-violations", status); |
| 67 | 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 | 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 | 41 | |
| 42 | 42 | import java.util.logging.Logger; |
| 43 | 43 | |
| 44 | -import javax.ws.rs.Produces; | |
| 45 | 44 | import javax.ws.rs.core.Response; |
| 46 | 45 | import javax.ws.rs.ext.ExceptionMapper; |
| 47 | 46 | import javax.ws.rs.ext.Provider; |
| ... | ... | @@ -59,14 +58,13 @@ public class AuthorizationExceptionMapper implements ExceptionMapper<Authorizati |
| 59 | 58 | private transient Logger logger; |
| 60 | 59 | |
| 61 | 60 | @Override |
| 62 | - @Produces("text/plain") | |
| 63 | 61 | public Response toResponse(AuthorizationException exception) { |
| 64 | 62 | int status = SC_FORBIDDEN; |
| 65 | 63 | |
| 66 | 64 | String message = getBundle().getString("mapping-violations", status); |
| 67 | 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 | 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 | 157 | |
| 158 | 158 | private void setUnauthorizedStatus(HttpServletResponse response, AuthenticationException cause) throws IOException { |
| 159 | 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 | 168 | private Logger getLogger() { |
| 173 | 169 | if (logger == null) { | ... | ... |