Commit 7f7dc517c5e2ecfbc149573cf446affd6b2379e6
1 parent
cc27007b
Exists in
master
Organização do fonte.
Showing
7 changed files
with
120 additions
and
164 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/auth.js
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/proxy/bookmark.js
| ... | ... | @@ -7,7 +7,7 @@ var BookmarkProxy = { |
| 7 | 7 | type : "GET", |
| 8 | 8 | url : this.url, |
| 9 | 9 | beforeSend : function(request) { |
| 10 | - request.setRequestHeader("Authorization", App.getToken()); | |
| 10 | + App.setHeader(request) | |
| 11 | 11 | } |
| 12 | 12 | }); |
| 13 | 13 | }, |
| ... | ... | @@ -17,7 +17,7 @@ var BookmarkProxy = { |
| 17 | 17 | type : "GET", |
| 18 | 18 | url : this.url + "/" + $id, |
| 19 | 19 | beforeSend : function(request) { |
| 20 | - request.setRequestHeader("Authorization", App.getToken()); | |
| 20 | + App.setHeader(request) | |
| 21 | 21 | } |
| 22 | 22 | }); |
| 23 | 23 | }, |
| ... | ... | @@ -29,7 +29,7 @@ var BookmarkProxy = { |
| 29 | 29 | data : JSON.stringify($data), |
| 30 | 30 | contentType : "application/json", |
| 31 | 31 | beforeSend : function(request) { |
| 32 | - request.setRequestHeader("Authorization", App.getToken()); | |
| 32 | + App.setHeader(request) | |
| 33 | 33 | } |
| 34 | 34 | }); |
| 35 | 35 | }, |
| ... | ... | @@ -41,7 +41,7 @@ var BookmarkProxy = { |
| 41 | 41 | data : JSON.stringify($data), |
| 42 | 42 | contentType : "application/json", |
| 43 | 43 | beforeSend : function(request) { |
| 44 | - request.setRequestHeader("Authorization", App.getToken()); | |
| 44 | + App.setHeader(request) | |
| 45 | 45 | } |
| 46 | 46 | }); |
| 47 | 47 | }, |
| ... | ... | @@ -53,7 +53,7 @@ var BookmarkProxy = { |
| 53 | 53 | data : JSON.stringify($ids), |
| 54 | 54 | contentType : "application/json", |
| 55 | 55 | beforeSend : function(request) { |
| 56 | - request.setRequestHeader("Authorization", App.getToken()); | |
| 56 | + App.setHeader(request) | |
| 57 | 57 | } |
| 58 | 58 | }); |
| 59 | 59 | } | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ParseExceptionMapper.java
| 1 | -package br.gov.frameworkdemoiselle.internal.implementation; | |
| 2 | - | |
| 3 | -import java.util.Arrays; | |
| 4 | -import java.util.HashSet; | |
| 5 | -import java.util.ResourceBundle; | |
| 6 | -import java.util.Set; | |
| 7 | - | |
| 8 | -import javax.ws.rs.core.Response; | |
| 9 | -import javax.ws.rs.ext.ExceptionMapper; | |
| 10 | -import javax.ws.rs.ext.Provider; | |
| 11 | - | |
| 12 | -import org.slf4j.Logger; | |
| 13 | - | |
| 14 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 15 | -import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 16 | - | |
| 17 | -@Provider | |
| 18 | -public class ParseExceptionMapper implements ExceptionMapper<Throwable> { | |
| 19 | - | |
| 20 | - private transient ResourceBundle bundle; | |
| 21 | - | |
| 22 | - private transient Logger logger; | |
| 23 | - | |
| 24 | - private Set<Class<?>> getTypes(Class<?> target) { | |
| 25 | - Set<Class<?>> classesInterfaces = new HashSet<Class<?>>(); | |
| 26 | - classesInterfaces.add(target); | |
| 27 | - classesInterfaces.addAll(Arrays.asList(target.getInterfaces())); | |
| 28 | - | |
| 29 | - Class<?> superClass = target.getSuperclass(); | |
| 30 | - | |
| 31 | - if (superClass != null) { | |
| 32 | - classesInterfaces.add(superClass); | |
| 33 | - classesInterfaces.addAll(getTypes(superClass)); | |
| 34 | - } | |
| 35 | - | |
| 36 | - return classesInterfaces; | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Override | |
| 40 | - public Response toResponse(Throwable exception) { | |
| 41 | - | |
| 42 | - // Throwable original = exception; | |
| 43 | - // | |
| 44 | - // while (exception != null) { | |
| 45 | - // System.out.println("xxxxxxxxxxxxxxxxxxxxxx : " + exception.getClass().getCanonicalName()); | |
| 46 | - // | |
| 47 | - // exception = exception.getCause(); | |
| 48 | - // } | |
| 49 | - // | |
| 50 | - // exception = original; | |
| 51 | - // | |
| 52 | - // Class<> | |
| 53 | - // | |
| 54 | - // while (exception != null) { | |
| 55 | - // System.out.println("xxxxxxxxxxxxxxxxxxxxxx : " + exception.getClass().getIgetCanonicalName()); | |
| 56 | - // | |
| 57 | - // exception.getClass().getSuperclass(); | |
| 58 | - // | |
| 59 | - // exception = exception.getP; | |
| 60 | - // } | |
| 61 | - | |
| 62 | - for (Class<?> type : getTypes(exception.getClass())) { | |
| 63 | - | |
| 64 | - System.out.println("___________________ " + type.getCanonicalName()); | |
| 65 | - | |
| 66 | - if (type.getCanonicalName().toLowerCase().indexOf("unrecognized") > -1) { | |
| 67 | - getLogger().error("XXXXXXXXXXXXXX", exception); | |
| 68 | - return Response.status(400).build(); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - // System.out.println("xxxxxxxxxxxxxx : " + getTypes(exception.getClass())); | |
| 73 | - | |
| 74 | - // if (exception.getMessage().toLowerCase().indexOf("unrecognized") > -1) { | |
| 75 | - // getLogger().error("XXXXXXXXXXXXXX", exception); | |
| 76 | - // return Response.status(400).build(); | |
| 77 | - // } | |
| 78 | - // | |
| 79 | - throw new RuntimeException(exception); | |
| 80 | - | |
| 81 | - // return null; | |
| 82 | - } | |
| 83 | - | |
| 84 | - private ResourceBundle getBundle() { | |
| 85 | - if (bundle == null) { | |
| 86 | - bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-rest-bundle")); | |
| 87 | - } | |
| 88 | - | |
| 89 | - return bundle; | |
| 90 | - } | |
| 91 | - | |
| 92 | - private Logger getLogger() { | |
| 93 | - if (logger == null) { | |
| 94 | - logger = Beans.getReference(Logger.class, new NameQualifier(ParseExceptionMapper.class.getName())); | |
| 95 | - } | |
| 96 | - | |
| 97 | - return logger; | |
| 98 | - } | |
| 99 | -} | |
| 1 | +//package br.gov.frameworkdemoiselle.internal.implementation; | |
| 2 | +// | |
| 3 | +//import java.util.Arrays; | |
| 4 | +//import java.util.HashSet; | |
| 5 | +//import java.util.ResourceBundle; | |
| 6 | +//import java.util.Set; | |
| 7 | +// | |
| 8 | +//import javax.ws.rs.core.Response; | |
| 9 | +//import javax.ws.rs.ext.ExceptionMapper; | |
| 10 | +//import javax.ws.rs.ext.Provider; | |
| 11 | +// | |
| 12 | +//import org.slf4j.Logger; | |
| 13 | +// | |
| 14 | +//import br.gov.frameworkdemoiselle.util.Beans; | |
| 15 | +//import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 16 | +// | |
| 17 | +//@Provider | |
| 18 | +//public class ParseExceptionMapper implements ExceptionMapper<Throwable> { | |
| 19 | +// | |
| 20 | +// private transient ResourceBundle bundle; | |
| 21 | +// | |
| 22 | +// private transient Logger logger; | |
| 23 | +// | |
| 24 | +// private Set<Class<?>> getTypes(Class<?> target) { | |
| 25 | +// Set<Class<?>> classesInterfaces = new HashSet<Class<?>>(); | |
| 26 | +// classesInterfaces.add(target); | |
| 27 | +// classesInterfaces.addAll(Arrays.asList(target.getInterfaces())); | |
| 28 | +// | |
| 29 | +// Class<?> superClass = target.getSuperclass(); | |
| 30 | +// | |
| 31 | +// if (superClass != null) { | |
| 32 | +// classesInterfaces.add(superClass); | |
| 33 | +// classesInterfaces.addAll(getTypes(superClass)); | |
| 34 | +// } | |
| 35 | +// | |
| 36 | +// return classesInterfaces; | |
| 37 | +// } | |
| 38 | +// | |
| 39 | +// @Override | |
| 40 | +// public Response toResponse(Throwable exception) { | |
| 41 | +// | |
| 42 | +// // Throwable original = exception; | |
| 43 | +// // | |
| 44 | +// // while (exception != null) { | |
| 45 | +// // System.out.println("xxxxxxxxxxxxxxxxxxxxxx : " + exception.getClass().getCanonicalName()); | |
| 46 | +// // | |
| 47 | +// // exception = exception.getCause(); | |
| 48 | +// // } | |
| 49 | +// // | |
| 50 | +// // exception = original; | |
| 51 | +// // | |
| 52 | +// // Class<> | |
| 53 | +// // | |
| 54 | +// // while (exception != null) { | |
| 55 | +// // System.out.println("xxxxxxxxxxxxxxxxxxxxxx : " + exception.getClass().getIgetCanonicalName()); | |
| 56 | +// // | |
| 57 | +// // exception.getClass().getSuperclass(); | |
| 58 | +// // | |
| 59 | +// // exception = exception.getP; | |
| 60 | +// // } | |
| 61 | +// | |
| 62 | +// for (Class<?> type : getTypes(exception.getClass())) { | |
| 63 | +// | |
| 64 | +// System.out.println("___________________ " + type.getCanonicalName()); | |
| 65 | +// | |
| 66 | +// if (type.getCanonicalName().toLowerCase().indexOf("unrecognized") > -1) { | |
| 67 | +// getLogger().error("XXXXXXXXXXXXXX", exception); | |
| 68 | +// return Response.status(400).build(); | |
| 69 | +// } | |
| 70 | +// } | |
| 71 | +// | |
| 72 | +// exception.printStackTrace(); | |
| 73 | +// | |
| 74 | +// return null; | |
| 75 | +// } | |
| 76 | +// | |
| 77 | +// private ResourceBundle getBundle() { | |
| 78 | +// if (bundle == null) { | |
| 79 | +// bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-rest-bundle")); | |
| 80 | +// } | |
| 81 | +// | |
| 82 | +// return bundle; | |
| 83 | +// } | |
| 84 | +// | |
| 85 | +// private Logger getLogger() { | |
| 86 | +// if (logger == null) { | |
| 87 | +// logger = Beans.getReference(Logger.class, new NameQualifier(ParseExceptionMapper.class.getName())); | |
| 88 | +// } | |
| 89 | +// | |
| 90 | +// return logger; | |
| 91 | +// } | |
| 92 | +//} | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/AbstractHTTPAuthorizationFilter.java
| ... | ... | @@ -75,34 +75,6 @@ public abstract class AbstractHTTPAuthorizationFilter implements Filter { |
| 75 | 75 | } else { |
| 76 | 76 | chain.doFilter(request, response); |
| 77 | 77 | } |
| 78 | - | |
| 79 | - // boolean processed = false; | |
| 80 | - // | |
| 81 | - // if (request instanceof HttpServletRequest) { | |
| 82 | - // HttpServletRequest httpRequest = (HttpServletRequest) request; | |
| 83 | - // HttpServletResponse httpResponse = (HttpServletResponse) response; | |
| 84 | - // | |
| 85 | - // String authHeader = getAuthHeader(httpRequest); | |
| 86 | - // String httpCredentials = extractCredentials(authHeader); | |
| 87 | - // | |
| 88 | - // RESTSecurityConfig config = Beans.getReference(RESTSecurityConfig.class); | |
| 89 | - // if (isActive(config) && isSupported(httpCredentials)) { | |
| 90 | - // processed = true; | |
| 91 | - // | |
| 92 | - // try { | |
| 93 | - // performLogin(httpCredentials, httpRequest, httpResponse); | |
| 94 | - // chain.doFilter(httpRequest, httpResponse); | |
| 95 | - // performLogout(httpCredentials, httpRequest, httpResponse); | |
| 96 | - // | |
| 97 | - // } catch (InvalidCredentialsException cause) { | |
| 98 | - // setUnauthorizedStatus(httpResponse, cause); | |
| 99 | - // } | |
| 100 | - // } | |
| 101 | - // } | |
| 102 | - // | |
| 103 | - // if (!processed) { | |
| 104 | - // chain.doFilter(request, response); | |
| 105 | - // } | |
| 106 | 78 | } |
| 107 | 79 | |
| 108 | 80 | protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| ... | ... | @@ -176,7 +148,7 @@ public abstract class AbstractHTTPAuthorizationFilter implements Filter { |
| 176 | 148 | |
| 177 | 149 | private void setUnauthorizedStatus(HttpServletResponse response, AuthenticationException cause) throws IOException { |
| 178 | 150 | response.setStatus(SC_UNAUTHORIZED); |
| 179 | - response.setContentType("text/plain"); | |
| 151 | + response.setContentType("text/plain; charset=UTF-8"); | |
| 180 | 152 | response.getWriter().write(cause.getMessage()); |
| 181 | 153 | } |
| 182 | 154 | } | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/BasicAuthFilter.java
| ... | ... | @@ -45,39 +45,38 @@ import br.gov.frameworkdemoiselle.util.Beans; |
| 45 | 45 | |
| 46 | 46 | public class BasicAuthFilter extends AbstractHTTPAuthorizationFilter { |
| 47 | 47 | |
| 48 | - private String credentials; | |
| 49 | - | |
| 50 | 48 | @Override |
| 51 | 49 | protected String getType() { |
| 52 | 50 | return "Basic"; |
| 53 | 51 | } |
| 54 | 52 | |
| 55 | 53 | @Override |
| 56 | - protected boolean isActive() { | |
| 57 | - return Beans.getReference(RESTSecurityConfig.class).isBasicFilterActive(); | |
| 58 | - } | |
| 59 | - | |
| 60 | - @Override | |
| 61 | - protected void performLogin(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { | |
| 62 | - String[] basicCredentials = getCredentials(credentials); | |
| 54 | + protected void performLogin(HttpServletRequest request, HttpServletResponse response) { | |
| 55 | + String[] decoded = decodeCredentials(request); | |
| 63 | 56 | |
| 64 | 57 | Credentials credentials = Beans.getReference(Credentials.class); |
| 65 | - credentials.setUsername(basicCredentials[0]); | |
| 66 | - credentials.setPassword(basicCredentials[1]); | |
| 58 | + credentials.setUsername(decoded[0]); | |
| 59 | + credentials.setPassword(decoded[1]); | |
| 67 | 60 | |
| 68 | - super.performLogin(httpRequest, httpResponse); | |
| 61 | + super.performLogin(request, response); | |
| 69 | 62 | } |
| 70 | 63 | |
| 71 | - private static String[] getCredentials(String header) throws InvalidCredentialsException { | |
| 64 | + private String[] decodeCredentials(HttpServletRequest request) throws InvalidCredentialsException { | |
| 72 | 65 | String[] result = null; |
| 73 | 66 | |
| 74 | - byte[] decoded = Base64.decodeBase64(header); | |
| 67 | + String authData = getAuthData(request); | |
| 68 | + byte[] decoded = Base64.decodeBase64(authData); | |
| 75 | 69 | result = new String(decoded).split(":"); |
| 76 | 70 | |
| 77 | 71 | if (result == null || result.length != 2) { |
| 78 | - throw new InvalidCredentialsException("Formato inválido do cabeçalho"); | |
| 72 | + throw new InvalidCredentialsException("formato inválido do cabeçalho"); | |
| 79 | 73 | } |
| 80 | 74 | |
| 81 | 75 | return result; |
| 82 | 76 | } |
| 77 | + | |
| 78 | + @Override | |
| 79 | + protected boolean isActive() { | |
| 80 | + return Beans.getReference(RESTSecurityConfig.class).isBasicFilterActive(); | |
| 81 | + } | |
| 83 | 82 | } | ... | ... |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/security/TokenAuthFilter.java
| ... | ... | @@ -66,11 +66,6 @@ public class TokenAuthFilter extends AbstractHTTPAuthorizationFilter { |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | @Override |
| 69 | - protected boolean isActive() { | |
| 70 | - return Beans.getReference(RESTSecurityConfig.class).isTokenFilterActive(); | |
| 71 | - } | |
| 72 | - | |
| 73 | - @Override | |
| 74 | 69 | protected void performLogin(HttpServletRequest request, HttpServletResponse response) { |
| 75 | 70 | Token token = Beans.getReference(Token.class); |
| 76 | 71 | String authData = getAuthData(request); |
| ... | ... | @@ -79,12 +74,9 @@ public class TokenAuthFilter extends AbstractHTTPAuthorizationFilter { |
| 79 | 74 | super.performLogin(request, response); |
| 80 | 75 | } |
| 81 | 76 | |
| 82 | - // public void setHeader(@Observes AfterLoginSuccessful event) { | |
| 83 | - // Token token = Beans.getReference(Token.class); | |
| 84 | - // | |
| 85 | - // if (!token.isEmpty()) { | |
| 86 | - // HttpServletResponse response = Beans.getReference(HttpServletResponse.class); | |
| 87 | - // response.setHeader("Set-Token", token.getValue()); | |
| 88 | - // } | |
| 89 | - // } | |
| 77 | + @Override | |
| 78 | + protected boolean isActive() { | |
| 79 | + return Beans.getReference(RESTSecurityConfig.class).isTokenFilterActive(); | |
| 80 | + } | |
| 81 | + | |
| 90 | 82 | } | ... | ... |
impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties
| ... | ... | @@ -33,5 +33,5 @@ |
| 33 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | |
| 36 | -has-permission-not-supported=N\u00E3o \u00E9 poss\u00EDvel utilizar @{0}, pois esta funcionalidade n\u00E3o \u00E9 suportada pelo JAAS. | |
| 37 | -authentication-failed=Falha no processo de autentica\u00E7\u00E3o. | |
| 36 | +has-permission-not-supported=N\u00e3o \u00e9 poss\u00edvel utilizar @{0}, pois esta funcionalidade n\u00e3o \u00e9 suportada pelo JAAS. | |
| 37 | +authentication-failed=Falha no processo de autentica\u00E7\u00E3o | ... | ... |