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 @@ -
- - - -