Commit 879c146b0c783abcdb31c201da322022629cdbf8
1 parent
902c6576
Exists in
master
Atualização do arquétipo
Showing
7 changed files
with
30 additions
and
24 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java
1 | 1 | package ${package}.security; |
2 | 2 | |
3 | 3 | import javax.enterprise.context.RequestScoped; |
4 | -import javax.inject.Inject; | |
5 | 4 | |
6 | 5 | import br.gov.frameworkdemoiselle.security.Authenticator; |
7 | 6 | import br.gov.frameworkdemoiselle.security.Credentials; |
8 | 7 | import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; |
9 | 8 | import br.gov.frameworkdemoiselle.security.User; |
9 | +import br.gov.frameworkdemoiselle.util.Beans; | |
10 | 10 | |
11 | 11 | @RequestScoped |
12 | 12 | public class AppAuthenticator implements Authenticator { |
13 | 13 | |
14 | 14 | private static final long serialVersionUID = 1L; |
15 | 15 | |
16 | - @Inject | |
17 | - private Credentials credentials; | |
18 | - | |
19 | 16 | private User user; |
20 | 17 | |
21 | 18 | @Override |
22 | 19 | public void authenticate() throws Exception { |
23 | - if ("admin".equals(credentials.getUsername()) && "admin".equals(credentials.getPassword())) { | |
20 | + Credentials credentials = Beans.getReference(Credentials.class); | |
21 | + | |
22 | + if (credentials.getUsername().equals("admin") && credentials.getPassword().equals("admin")) { | |
24 | 23 | this.user = new AppUser(credentials.getUsername()); |
25 | 24 | } else { |
26 | - throw new InvalidCredentialsException("usuário ou senha inválidos"); | |
25 | + throw new InvalidCredentialsException(); | |
27 | 26 | } |
28 | 27 | } |
29 | 28 | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/js/controller/login.js
1 | 1 | $(function() { |
2 | - | |
3 | 2 | $("#username").focus(); |
4 | 3 | |
5 | 4 | $("form").submit(function(event) { |
... | ... | @@ -17,16 +16,15 @@ $(function() { |
17 | 16 | |
18 | 17 | // Função utilitária |
19 | 18 | function make_base_auth(user, password) { |
20 | - var tok = user + ':' + password; | |
21 | - var hash = btoa(tok); | |
22 | - return "Basic " + hash; | |
19 | + var tok = user + ':' + password; | |
20 | + var hash = btoa(tok); | |
21 | + return "Basic " + hash; | |
23 | 22 | } |
24 | 23 | |
25 | 24 | // Funções de Callback |
26 | 25 | |
27 | 26 | function loginOk(data) { |
28 | - sessionStorage.setItem('credential', | |
29 | - make_base_auth($("#username").val().trim(), $("#password").val().trim())); | |
27 | + sessionStorage.setItem('credential', make_base_auth($("#username").val().trim(), $("#password").val().trim())); | |
30 | 28 | location.href = "bookmark-list.html"; |
31 | 29 | } |
32 | 30 | |
... | ... | @@ -36,6 +34,7 @@ function loginFail(request) { |
36 | 34 | case 401: |
37 | 35 | $("#global-message").html("Usuário ou senha inválidos.").show(); |
38 | 36 | break; |
37 | + | |
39 | 38 | case 412: |
40 | 39 | $($("form input").get().reverse()).each(function() { |
41 | 40 | var id = $(this).attr('id'); | ... | ... |
archetype/html-rest/src/main/resources/archetype-resources/src/main/webapp/login.html
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | -<head> | |
4 | - <meta charset="UTF-8"> | |
5 | - <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
6 | - <meta name="viewport" content="width=device-width, initial-scale=1"> | |
7 | - <title>Notifica | Login</title> | |
8 | - <link href="css/bootstrap.min.css" rel="stylesheet"> | |
9 | - <link href="css/bookmark.css" rel="stylesheet"> | |
3 | +<head> | |
4 | +<meta charset="UTF-8"> | |
5 | +<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
6 | +<meta name="viewport" content="width=device-width, initial-scale=1"> | |
7 | +<title>Notifica | Login</title> | |
8 | +<link href="css/bootstrap.min.css" rel="stylesheet"> | |
9 | +<link href="css/bookmark.css" rel="stylesheet"> | |
10 | 10 | </head> |
11 | 11 | <body> |
12 | 12 | <div class="container"> |
13 | - <form id="form-login" role="form"> | |
13 | + <form id="form-login" role="form"> | |
14 | 14 | <div class="col-md-4 col-md-offset-4"> |
15 | 15 | <div class="form-group"> |
16 | 16 | <h1>Bookmark | Login</h1> |
... | ... | @@ -18,14 +18,14 @@ |
18 | 18 | </div> |
19 | 19 | <div class="col-md-4 col-md-offset-4"> |
20 | 20 | <div class="form-group"> |
21 | - <label for="username">Login</label> | |
21 | + <label for="username">Login (admin)</label> | |
22 | 22 | <input id="username" type="text" class="form-control input-lg" /> |
23 | 23 | <div id="username-message" class="label label-danger" hidden="true"></div> |
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="col-md-4 col-md-offset-4"> |
27 | 27 | <div class="form-group"> |
28 | - <label for="password">Senha</label> | |
28 | + <label for="password">Senha (admin)</label> | |
29 | 29 | <input id="password" type="password" class="form-control input-lg" /> |
30 | 30 | <div id="password-message" class="label label-danger" hidden="true"></div> |
31 | 31 | </div> | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/InvalidCredentialsException.java
1 | 1 | package br.gov.frameworkdemoiselle.security; |
2 | 2 | |
3 | +import java.util.ResourceBundle; | |
4 | + | |
5 | +import br.gov.frameworkdemoiselle.util.Beans; | |
6 | + | |
3 | 7 | /** |
4 | 8 | * Thrown when the user's credentials are invalid. |
5 | 9 | * |
... | ... | @@ -9,6 +13,10 @@ public class InvalidCredentialsException extends AuthenticationException { |
9 | 13 | |
10 | 14 | private static final long serialVersionUID = 1L; |
11 | 15 | |
16 | + public InvalidCredentialsException() { | |
17 | + super(Beans.getReference(ResourceBundle.class).getString("invalid-credentials")); | |
18 | + } | |
19 | + | |
12 | 20 | /** |
13 | 21 | * Constructs an <code>InvalidCredentialsException</code> with a message. |
14 | 22 | */ | ... | ... |
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 |
96 | 96 | access-denied-ui=Voc\u00EA n\u00E3o est\u00E1 autorizado a executar a a\u00E7\u00E3o {1} no recurso {0} |
97 | 97 | 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. |
98 | 98 | user-not-authenticated=Usu\u00E1rio n\u00E3o autenticado |
99 | +invalid-credentials=Usu\u00E1rio ou senha inv\u00E1lidos | |
99 | 100 | has-role-verification=Verificando se o usu\u00E1rio {0} possui a(s) role(s)\: {1} |
100 | 101 | does-not-have-role=Usu\u00E1rio {0} n\u00E3o possui a(s) role(s)\: {1} |
101 | 102 | does-not-have-role-ui=Para acessar este recurso \u00E9 necess\u00E1rio ser {0} | ... | ... |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java
... | ... | @@ -71,7 +71,7 @@ public class ServletAuthenticator implements Authenticator { |
71 | 71 | if (cause.getMessage().toLowerCase().contains("invalid") |
72 | 72 | || cause.getMessage().toLowerCase().contains("incorrect") |
73 | 73 | || cause.getMessage().toLowerCase().contains("failed")) { |
74 | - throw new InvalidCredentialsException(getBundle().getString("invalid-credentials"), cause); | |
74 | + throw new InvalidCredentialsException(); | |
75 | 75 | } else { |
76 | 76 | throw new AuthenticationException(getBundle().getString("authentication-failed"), cause); |
77 | 77 | } | ... | ... |
impl/extension/servlet/src/main/resources/demoiselle-servlet-bundle.properties
... | ... | @@ -34,5 +34,4 @@ |
34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | 35 | |
36 | 36 | has-permission-not-supported=N\u00E3o \u00E9 poss\u00EDvel utilizar @{0}, pois esta funcionalidade n\u00E3o \u00E9 suportada pelo JAAS. |
37 | -invalid-credentials=Usu\u00E1rio ou senha inv\u00E1lidos. | |
38 | 37 | authentication-failed=Falha no processo de autentica\u00E7\u00E3o. | ... | ... |