Commit a9efdea107be6674c185bdc66af6271004110da8
1 parent
7681fc4a
Exists in
master
Ajustes nas interfaces e implementações do mecanismo de controle de
acesso
Showing
15 changed files
with
81 additions
and
34 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
... | ... | @@ -72,7 +72,7 @@ public class DefaultAuthenticator implements Authenticator { |
72 | 72 | * @see br.gov.frameworkdemoiselle.security.Authenticator#unAuthenticate() |
73 | 73 | */ |
74 | 74 | @Override |
75 | - public void unAuthenticate() { | |
75 | + public void unauthenticate() { | |
76 | 76 | throw getException(); |
77 | 77 | } |
78 | 78 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
... | ... | @@ -43,7 +43,9 @@ import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; |
43 | 43 | import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; |
44 | 44 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
45 | 45 | import br.gov.frameworkdemoiselle.security.Authenticator; |
46 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
46 | 47 | import br.gov.frameworkdemoiselle.security.Authorizer; |
48 | +import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | |
47 | 49 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
48 | 50 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
49 | 51 | import br.gov.frameworkdemoiselle.security.User; |
... | ... | @@ -61,7 +63,7 @@ public class SecurityContextImpl implements SecurityContext { |
61 | 63 | |
62 | 64 | private static final long serialVersionUID = 1L; |
63 | 65 | |
64 | - private transient ResourceBundle bundle; | |
66 | + private transient ResourceBundle bundle; | |
65 | 67 | |
66 | 68 | private Authenticator authenticator; |
67 | 69 | |
... | ... | @@ -99,26 +101,45 @@ public class SecurityContextImpl implements SecurityContext { |
99 | 101 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String) |
100 | 102 | */ |
101 | 103 | @Override |
102 | - public boolean hasPermission(String resource, String operation) throws NotLoggedInException { | |
104 | + public boolean hasPermission(String resource, String operation) { | |
105 | + boolean result = true; | |
106 | + | |
103 | 107 | if (getConfig().isEnabled()) { |
104 | 108 | checkLoggedIn(); |
105 | - return getAuthorizer().hasPermission(resource, operation); | |
106 | 109 | |
107 | - } else { | |
108 | - return true; | |
110 | + try { | |
111 | + result = getAuthorizer().hasPermission(resource, operation); | |
112 | + | |
113 | + } catch (AuthorizationException cause) { | |
114 | + throw cause; | |
115 | + | |
116 | + } catch (Exception cause) { | |
117 | + throw new AuthorizationException(cause); | |
118 | + } | |
109 | 119 | } |
120 | + | |
121 | + return result; | |
110 | 122 | } |
111 | 123 | |
112 | 124 | /** |
113 | 125 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasRole(java.lang.String) |
114 | 126 | */ |
115 | 127 | @Override |
116 | - public boolean hasRole(String role) throws NotLoggedInException { | |
128 | + public boolean hasRole(String role) { | |
117 | 129 | boolean result = true; |
118 | 130 | |
119 | 131 | if (getConfig().isEnabled()) { |
120 | 132 | checkLoggedIn(); |
121 | - result = getAuthorizer().hasRole(role); | |
133 | + | |
134 | + try { | |
135 | + result = getAuthorizer().hasRole(role); | |
136 | + | |
137 | + } catch (AuthorizationException cause) { | |
138 | + throw cause; | |
139 | + | |
140 | + } catch (Exception cause) { | |
141 | + throw new AuthorizationException(cause); | |
142 | + } | |
122 | 143 | } |
123 | 144 | |
124 | 145 | return result; |
... | ... | @@ -142,9 +163,21 @@ public class SecurityContextImpl implements SecurityContext { |
142 | 163 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#login() |
143 | 164 | */ |
144 | 165 | @Override |
145 | - public void login() throws AuthenticationException { | |
166 | + public void login() { | |
146 | 167 | if (getConfig().isEnabled()) { |
147 | - getAuthenticator().authenticate(); | |
168 | + | |
169 | + try { | |
170 | + getAuthenticator().authenticate(); | |
171 | + | |
172 | + } catch (InvalidCredentialsException cause) { | |
173 | + throw cause; | |
174 | + | |
175 | + } catch (AuthenticationException cause) { | |
176 | + throw cause; | |
177 | + | |
178 | + } catch (Exception cause) { | |
179 | + throw new AuthenticationException(cause); | |
180 | + } | |
148 | 181 | |
149 | 182 | Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() { |
150 | 183 | |
... | ... | @@ -161,7 +194,19 @@ public class SecurityContextImpl implements SecurityContext { |
161 | 194 | public void logout() throws NotLoggedInException { |
162 | 195 | if (getConfig().isEnabled()) { |
163 | 196 | checkLoggedIn(); |
164 | - getAuthenticator().unAuthenticate(); | |
197 | + | |
198 | + try { | |
199 | + getAuthenticator().unauthenticate(); | |
200 | + | |
201 | + } catch (InvalidCredentialsException cause) { | |
202 | + throw cause; | |
203 | + | |
204 | + } catch (AuthenticationException cause) { | |
205 | + throw cause; | |
206 | + | |
207 | + } catch (Exception cause) { | |
208 | + throw new AuthenticationException(cause); | |
209 | + } | |
165 | 210 | |
166 | 211 | Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() { |
167 | 212 | |
... | ... | @@ -194,7 +239,7 @@ public class SecurityContextImpl implements SecurityContext { |
194 | 239 | } |
195 | 240 | } |
196 | 241 | |
197 | - private ResourceBundle getBundle() { | |
242 | + private ResourceBundle getBundle() { | |
198 | 243 | if (bundle == null) { |
199 | 244 | bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); |
200 | 245 | } |
... | ... | @@ -202,7 +247,7 @@ public class SecurityContextImpl implements SecurityContext { |
202 | 247 | return bundle; |
203 | 248 | } |
204 | 249 | |
205 | - private static class EmptyUser implements User{ | |
250 | + private static class EmptyUser implements User { | |
206 | 251 | |
207 | 252 | private static final long serialVersionUID = 1L; |
208 | 253 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/AuthorizationException.java
... | ... | @@ -54,4 +54,14 @@ public class AuthorizationException extends SecurityException { |
54 | 54 | public AuthorizationException(String message) { |
55 | 55 | super(message); |
56 | 56 | } |
57 | + | |
58 | + /** | |
59 | + * Constructor with the cause. | |
60 | + * | |
61 | + * @param cause | |
62 | + * exception cause | |
63 | + */ | |
64 | + public AuthorizationException(Throwable cause) { | |
65 | + super(cause); | |
66 | + } | |
57 | 67 | } | ... | ... |
impl/core/src/test/java/configuration/field/beanvalidation/ConfigurationBeanValidationFieldTest.java
impl/core/src/test/java/management/testclasses/DummyManagementExtension.java
impl/core/src/test/java/security/athentication/ambiguity/DuplicatedCustomAuthenticator.java
... | ... | @@ -36,7 +36,6 @@ |
36 | 36 | */ |
37 | 37 | package security.athentication.ambiguity; |
38 | 38 | |
39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
40 | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
41 | 40 | import br.gov.frameworkdemoiselle.security.User; |
42 | 41 | |
... | ... | @@ -45,11 +44,11 @@ public class DuplicatedCustomAuthenticator implements Authenticator { |
45 | 44 | private static final long serialVersionUID = 1L; |
46 | 45 | |
47 | 46 | @Override |
48 | - public void authenticate() throws AuthenticationException { | |
47 | + public void authenticate() { | |
49 | 48 | } |
50 | 49 | |
51 | 50 | @Override |
52 | - public void unAuthenticate() { | |
51 | + public void unauthenticate() { | |
53 | 52 | } |
54 | 53 | |
55 | 54 | @Override | ... | ... |
impl/core/src/test/java/security/athentication/credentials/StrictAuthenticator.java
... | ... | @@ -48,7 +48,7 @@ public class StrictAuthenticator implements Authenticator { |
48 | 48 | private User currentUser; |
49 | 49 | |
50 | 50 | @Override |
51 | - public void authenticate() throws AuthenticationException { | |
51 | + public void authenticate() { | |
52 | 52 | |
53 | 53 | Credentials c = Beans.getReference(Credentials.class); |
54 | 54 | if ("demoiselle".equals(c.getLogin())) { |
... | ... | @@ -75,7 +75,7 @@ public class StrictAuthenticator implements Authenticator { |
75 | 75 | } |
76 | 76 | |
77 | 77 | @Override |
78 | - public void unAuthenticate() { | |
78 | + public void unauthenticate() { | |
79 | 79 | this.currentUser = null; |
80 | 80 | } |
81 | 81 | ... | ... |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticator.java
... | ... | @@ -36,7 +36,6 @@ |
36 | 36 | */ |
37 | 37 | package security.athentication.custom; |
38 | 38 | |
39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
40 | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
41 | 40 | import br.gov.frameworkdemoiselle.security.User; |
42 | 41 | |
... | ... | @@ -47,7 +46,7 @@ public class CustomAuthenticator implements Authenticator { |
47 | 46 | private User currentUser; |
48 | 47 | |
49 | 48 | @Override |
50 | - public void authenticate() throws AuthenticationException { | |
49 | + public void authenticate() { | |
51 | 50 | this.currentUser = new User() { |
52 | 51 | |
53 | 52 | private static final long serialVersionUID = 1L; |
... | ... | @@ -68,7 +67,7 @@ public class CustomAuthenticator implements Authenticator { |
68 | 67 | } |
69 | 68 | |
70 | 69 | @Override |
71 | - public void unAuthenticate() { | |
70 | + public void unauthenticate() { | |
72 | 71 | this.currentUser = null; |
73 | 72 | } |
74 | 73 | ... | ... |
impl/core/src/test/java/security/athentication/error/ErrorAuthenticator.java
... | ... | @@ -36,7 +36,6 @@ |
36 | 36 | */ |
37 | 37 | package security.athentication.error; |
38 | 38 | |
39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
40 | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
41 | 40 | import br.gov.frameworkdemoiselle.security.User; |
42 | 41 | |
... | ... | @@ -45,12 +44,12 @@ public class ErrorAuthenticator implements Authenticator { |
45 | 44 | private static final long serialVersionUID = 1L; |
46 | 45 | |
47 | 46 | @Override |
48 | - public void authenticate() throws AuthenticationException { | |
47 | + public void authenticate() { | |
49 | 48 | throw new RuntimeException(); |
50 | 49 | } |
51 | 50 | |
52 | 51 | @Override |
53 | - public void unAuthenticate() { | |
52 | + public void unauthenticate() { | |
54 | 53 | throw new RuntimeException(); |
55 | 54 | } |
56 | 55 | ... | ... |
impl/core/src/test/java/transaction/createdstrategy/TransactionWithCreatedStrategyTest.java
... | ... | @@ -47,11 +47,10 @@ import org.junit.Before; |
47 | 47 | import org.junit.Test; |
48 | 48 | import org.junit.runner.RunWith; |
49 | 49 | |
50 | +import test.Tests; | |
50 | 51 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
51 | 52 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
52 | 53 | |
53 | -import test.Tests; | |
54 | - | |
55 | 54 | @RunWith(Arquillian.class) |
56 | 55 | public class TransactionWithCreatedStrategyTest { |
57 | 56 | ... | ... |
impl/core/src/test/java/transaction/defaultstrategy/TransactionDefaultTest.java
... | ... | @@ -45,12 +45,11 @@ import org.junit.Before; |
45 | 45 | import org.junit.Test; |
46 | 46 | import org.junit.runner.RunWith; |
47 | 47 | |
48 | +import test.Tests; | |
48 | 49 | import br.gov.frameworkdemoiselle.DemoiselleException; |
49 | 50 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
50 | 51 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
51 | 52 | |
52 | -import test.Tests; | |
53 | - | |
54 | 53 | @RunWith(Arquillian.class) |
55 | 54 | public class TransactionDefaultTest { |
56 | 55 | ... | ... |
impl/core/src/test/java/util/beans/BeansTest.java
impl/core/src/test/java/util/beans/QualifierOne.java
... | ... | @@ -38,8 +38,8 @@ package util.beans; |
38 | 38 | |
39 | 39 | import static java.lang.annotation.ElementType.FIELD; |
40 | 40 | import static java.lang.annotation.ElementType.METHOD; |
41 | -import static java.lang.annotation.ElementType.TYPE; | |
42 | 41 | import static java.lang.annotation.ElementType.PARAMETER; |
42 | +import static java.lang.annotation.ElementType.TYPE; | |
43 | 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
44 | 44 | |
45 | 45 | import java.lang.annotation.Retention; | ... | ... |
impl/core/src/test/java/util/beans/QualifierTwo.java
... | ... | @@ -38,8 +38,8 @@ package util.beans; |
38 | 38 | |
39 | 39 | import static java.lang.annotation.ElementType.FIELD; |
40 | 40 | import static java.lang.annotation.ElementType.METHOD; |
41 | -import static java.lang.annotation.ElementType.TYPE; | |
42 | 41 | import static java.lang.annotation.ElementType.PARAMETER; |
42 | +import static java.lang.annotation.ElementType.TYPE; | |
43 | 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
44 | 44 | |
45 | 45 | import java.lang.annotation.Retention; | ... | ... |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java