Commit ca09e480acd53d2821527c79a4477592624a5436
1 parent
0a8b6304
Exists in
master
Utilização do logger e resource bundle
Showing
2 changed files
with
25 additions
and
15 deletions
Show diff stats
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthenticator.java
@@ -52,8 +52,11 @@ import javax.security.auth.callback.UnsupportedCallbackException; | @@ -52,8 +52,11 @@ import javax.security.auth.callback.UnsupportedCallbackException; | ||
52 | import javax.security.auth.login.LoginContext; | 52 | import javax.security.auth.login.LoginContext; |
53 | import javax.security.auth.login.LoginException; | 53 | import javax.security.auth.login.LoginException; |
54 | 54 | ||
55 | +import org.slf4j.Logger; | ||
56 | + | ||
55 | import br.gov.frameworkdemoiselle.annotation.Priority; | 57 | import br.gov.frameworkdemoiselle.annotation.Priority; |
56 | import br.gov.frameworkdemoiselle.internal.configuration.JAASConfig; | 58 | import br.gov.frameworkdemoiselle.internal.configuration.JAASConfig; |
59 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | ||
57 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | 60 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
58 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 61 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
59 | import br.gov.frameworkdemoiselle.util.Strings; | 62 | import br.gov.frameworkdemoiselle.util.Strings; |
@@ -64,7 +67,9 @@ public class JAASAuthenticator implements Authenticator { | @@ -64,7 +67,9 @@ public class JAASAuthenticator implements Authenticator { | ||
64 | 67 | ||
65 | private static final long serialVersionUID = 1L; | 68 | private static final long serialVersionUID = 1L; |
66 | 69 | ||
67 | - private ResourceBundle bundle; | 70 | + private static ResourceBundle bundle; |
71 | + | ||
72 | + private static Logger logger; | ||
68 | 73 | ||
69 | private User user; | 74 | private User user; |
70 | 75 | ||
@@ -97,8 +102,7 @@ public class JAASAuthenticator implements Authenticator { | @@ -97,8 +102,7 @@ public class JAASAuthenticator implements Authenticator { | ||
97 | } | 102 | } |
98 | 103 | ||
99 | } catch (LoginException cause) { | 104 | } catch (LoginException cause) { |
100 | - // TODO Colocar no log | ||
101 | - result = false; | 105 | + getLogger().info(cause.getMessage()); |
102 | } | 106 | } |
103 | 107 | ||
104 | return result; | 108 | return result; |
@@ -162,20 +166,26 @@ public class JAASAuthenticator implements Authenticator { | @@ -162,20 +166,26 @@ public class JAASAuthenticator implements Authenticator { | ||
162 | ((PasswordCallback) callbacks[i]).setPassword(credentials.getPassword().toCharArray()); | 166 | ((PasswordCallback) callbacks[i]).setPassword(credentials.getPassword().toCharArray()); |
163 | 167 | ||
164 | } else { | 168 | } else { |
165 | - // TODO Utilizar o logger... | ||
166 | - | ||
167 | - System.out.println(getBundle().getString("unsupported-callback", callbacks[i])); | 169 | + getLogger().error(getBundle().getString("unsupported-callback", callbacks[i])); |
168 | } | 170 | } |
169 | } | 171 | } |
170 | } | 172 | } |
171 | }; | 173 | }; |
172 | } | 174 | } |
173 | 175 | ||
174 | - private ResourceBundle getBundle() { | ||
175 | - if (this.bundle == null) { | ||
176 | - this.bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | 176 | + private static ResourceBundle getBundle() { |
177 | + if (bundle == null) { | ||
178 | + bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | ||
179 | + } | ||
180 | + | ||
181 | + return bundle; | ||
182 | + } | ||
183 | + | ||
184 | + private static Logger getLogger() { | ||
185 | + if (logger == null) { | ||
186 | + logger = LoggerProducer.create(JAASAuthenticator.class); | ||
177 | } | 187 | } |
178 | 188 | ||
179 | - return this.bundle; | 189 | + return logger; |
180 | } | 190 | } |
181 | } | 191 | } |
impl/extension/jaas/src/main/java/br/gov/frameworkdemoiselle/security/JAASAuthorizer.java
@@ -55,7 +55,7 @@ public class JAASAuthorizer implements Authorizer { | @@ -55,7 +55,7 @@ public class JAASAuthorizer implements Authorizer { | ||
55 | 55 | ||
56 | private static final long serialVersionUID = 1L; | 56 | private static final long serialVersionUID = 1L; |
57 | 57 | ||
58 | - private ResourceBundle bundle; | 58 | + private static ResourceBundle bundle; |
59 | 59 | ||
60 | @Override | 60 | @Override |
61 | public boolean hasRole(String role) { | 61 | public boolean hasRole(String role) { |
@@ -92,11 +92,11 @@ public class JAASAuthorizer implements Authorizer { | @@ -92,11 +92,11 @@ public class JAASAuthorizer implements Authorizer { | ||
92 | RequiredPermission.class.getSimpleName())); | 92 | RequiredPermission.class.getSimpleName())); |
93 | } | 93 | } |
94 | 94 | ||
95 | - private ResourceBundle getBundle() { | ||
96 | - if (this.bundle == null) { | ||
97 | - this.bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | 95 | + private static ResourceBundle getBundle() { |
96 | + if (bundle == null) { | ||
97 | + bundle = ResourceBundleProducer.create("demoiselle-jaas-bundle"); | ||
98 | } | 98 | } |
99 | 99 | ||
100 | - return this.bundle; | 100 | + return bundle; |
101 | } | 101 | } |
102 | } | 102 | } |