diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java index a24e32e..fc348b5 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java @@ -1,29 +1,28 @@ package ${package}.security; import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; import br.gov.frameworkdemoiselle.security.Authenticator; import br.gov.frameworkdemoiselle.security.Credentials; import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; import br.gov.frameworkdemoiselle.security.User; +import br.gov.frameworkdemoiselle.util.Beans; @RequestScoped public class AppAuthenticator implements Authenticator { private static final long serialVersionUID = 1L; - @Inject - private Credentials credentials; - private User user; @Override public void authenticate() throws Exception { - if ("admin".equals(credentials.getUsername()) && "admin".equals(credentials.getPassword())) { + Credentials credentials = Beans.getReference(Credentials.class); + + if (credentials.getUsername().equals("admin") && credentials.getPassword().equals("admin")) { this.user = new AppUser(credentials.getUsername()); } else { - throw new InvalidCredentialsException("usuário ou senha inválidos"); + throw new InvalidCredentialsException(); } } diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js index 7e40565..cf979b3 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js @@ -1,5 +1,4 @@ $(function() { - $("#username").focus(); $("form").submit(function(event) { @@ -17,16 +16,15 @@ $(function() { // Função utilitária function make_base_auth(user, password) { - var tok = user + ':' + password; - var hash = btoa(tok); - return "Basic " + hash; + var tok = user + ':' + password; + var hash = btoa(tok); + return "Basic " + hash; } // Funções de Callback function loginOk(data) { - sessionStorage.setItem('credential', - make_base_auth($("#username").val().trim(), $("#password").val().trim())); + sessionStorage.setItem('credential', make_base_auth($("#username").val().trim(), $("#password").val().trim())); location.href = "bookmark-list.html"; } @@ -36,6 +34,7 @@ function loginFail(request) { case 401: $("#global-message").html("Usuário ou senha inválidos.").show(); break; + case 412: $($("form input").get().reverse()).each(function() { var id = $(this).attr('id'); diff --git a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html index 695f564..bedf33c 100644 --- a/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html +++ b/archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html @@ -1,16 +1,16 @@ - - - - - Notifica | Login - - + + + + +Notifica | Login + +
-
+

Bookmark | Login

@@ -18,14 +18,14 @@
- +
- +
diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/InvalidCredentialsException.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/InvalidCredentialsException.java index faeb7d6..e036662 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/InvalidCredentialsException.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/InvalidCredentialsException.java @@ -1,5 +1,9 @@ package br.gov.frameworkdemoiselle.security; +import java.util.ResourceBundle; + +import br.gov.frameworkdemoiselle.util.Beans; + /** * Thrown when the user's credentials are invalid. * @@ -9,6 +13,10 @@ public class InvalidCredentialsException extends AuthenticationException { private static final long serialVersionUID = 1L; + public InvalidCredentialsException() { + super(Beans.getReference(ResourceBundle.class).getString("invalid-credentials")); + } + /** * Constructs an InvalidCredentialsException with a message. */ diff --git a/impl/core/src/main/resources/demoiselle-core-bundle.properties b/impl/core/src/main/resources/demoiselle-core-bundle.properties index 6124859..1702315 100644 --- a/impl/core/src/main/resources/demoiselle-core-bundle.properties +++ b/impl/core/src/main/resources/demoiselle-core-bundle.properties @@ -96,6 +96,7 @@ access-denied=O usu\u00E1rio {0} n\u00E3o possui permiss\u00E3o para executar a access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} authorizer-not-defined=Nenhuma regra de resolu\u00E7\u00E3o de permiss\u00F5es foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authorizer.class como regra de resolu\u00E7\u00E3o de permiss\u00F5es desejada no arquivo demoiselle.properties. user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado +invalid-credentials=Usu\u00E1rio ou senha inv\u00E1lidos has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} diff --git a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java index f59ecd9..769cf30 100644 --- a/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java +++ b/impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java @@ -71,7 +71,7 @@ public class ServletAuthenticator implements Authenticator { if (cause.getMessage().toLowerCase().contains("invalid") || cause.getMessage().toLowerCase().contains("incorrect") || cause.getMessage().toLowerCase().contains("failed")) { - throw new InvalidCredentialsException(getBundle().getString("invalid-credentials"), cause); + throw new InvalidCredentialsException(); } else { throw new AuthenticationException(getBundle().getString("authentication-failed"), cause); } diff --git a/impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties b/impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties index 59e36d6..fb4f36f 100644 --- a/impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties +++ b/impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties @@ -34,5 +34,4 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. has-permission-not-supported=N\u00E3o \u00E9 poss\u00EDvel utilizar @{0}, pois esta funcionalidade n\u00E3o \u00E9 suportada pelo JAAS. -invalid-credentials=Usu\u00E1rio ou senha inv\u00E1lidos. authentication-failed=Falha no processo de autentica\u00E7\u00E3o. -- libgit2 0.21.2