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,7 +72,7 @@ public class DefaultAuthenticator implements Authenticator { | ||
| 72 | * @see br.gov.frameworkdemoiselle.security.Authenticator#unAuthenticate() | 72 | * @see br.gov.frameworkdemoiselle.security.Authenticator#unAuthenticate() |
| 73 | */ | 73 | */ |
| 74 | @Override | 74 | @Override |
| 75 | - public void unAuthenticate() { | 75 | + public void unauthenticate() { |
| 76 | throw getException(); | 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,7 +43,9 @@ import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; | ||
| 43 | import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; | 43 | import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; |
| 44 | import br.gov.frameworkdemoiselle.security.AuthenticationException; | 44 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 45 | import br.gov.frameworkdemoiselle.security.Authenticator; | 45 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 46 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | ||
| 46 | import br.gov.frameworkdemoiselle.security.Authorizer; | 47 | import br.gov.frameworkdemoiselle.security.Authorizer; |
| 48 | +import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | ||
| 47 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; | 49 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
| 48 | import br.gov.frameworkdemoiselle.security.SecurityContext; | 50 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 49 | import br.gov.frameworkdemoiselle.security.User; | 51 | import br.gov.frameworkdemoiselle.security.User; |
| @@ -61,7 +63,7 @@ public class SecurityContextImpl implements SecurityContext { | @@ -61,7 +63,7 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 61 | 63 | ||
| 62 | private static final long serialVersionUID = 1L; | 64 | private static final long serialVersionUID = 1L; |
| 63 | 65 | ||
| 64 | - private transient ResourceBundle bundle; | 66 | + private transient ResourceBundle bundle; |
| 65 | 67 | ||
| 66 | private Authenticator authenticator; | 68 | private Authenticator authenticator; |
| 67 | 69 | ||
| @@ -99,26 +101,45 @@ public class SecurityContextImpl implements SecurityContext { | @@ -99,26 +101,45 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 99 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String) | 101 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasPermission(java.lang.String, java.lang.String) |
| 100 | */ | 102 | */ |
| 101 | @Override | 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 | if (getConfig().isEnabled()) { | 107 | if (getConfig().isEnabled()) { |
| 104 | checkLoggedIn(); | 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 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasRole(java.lang.String) | 125 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#hasRole(java.lang.String) |
| 114 | */ | 126 | */ |
| 115 | @Override | 127 | @Override |
| 116 | - public boolean hasRole(String role) throws NotLoggedInException { | 128 | + public boolean hasRole(String role) { |
| 117 | boolean result = true; | 129 | boolean result = true; |
| 118 | 130 | ||
| 119 | if (getConfig().isEnabled()) { | 131 | if (getConfig().isEnabled()) { |
| 120 | checkLoggedIn(); | 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 | return result; | 145 | return result; |
| @@ -142,9 +163,21 @@ public class SecurityContextImpl implements SecurityContext { | @@ -142,9 +163,21 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 142 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#login() | 163 | * @see br.gov.frameworkdemoiselle.security.SecurityContext#login() |
| 143 | */ | 164 | */ |
| 144 | @Override | 165 | @Override |
| 145 | - public void login() throws AuthenticationException { | 166 | + public void login() { |
| 146 | if (getConfig().isEnabled()) { | 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 | Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() { | 182 | Beans.getBeanManager().fireEvent(new AfterLoginSuccessful() { |
| 150 | 183 | ||
| @@ -161,7 +194,19 @@ public class SecurityContextImpl implements SecurityContext { | @@ -161,7 +194,19 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 161 | public void logout() throws NotLoggedInException { | 194 | public void logout() throws NotLoggedInException { |
| 162 | if (getConfig().isEnabled()) { | 195 | if (getConfig().isEnabled()) { |
| 163 | checkLoggedIn(); | 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 | Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() { | 211 | Beans.getBeanManager().fireEvent(new AfterLogoutSuccessful() { |
| 167 | 212 | ||
| @@ -194,7 +239,7 @@ public class SecurityContextImpl implements SecurityContext { | @@ -194,7 +239,7 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 194 | } | 239 | } |
| 195 | } | 240 | } |
| 196 | 241 | ||
| 197 | - private ResourceBundle getBundle() { | 242 | + private ResourceBundle getBundle() { |
| 198 | if (bundle == null) { | 243 | if (bundle == null) { |
| 199 | bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | 244 | bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); |
| 200 | } | 245 | } |
| @@ -202,7 +247,7 @@ public class SecurityContextImpl implements SecurityContext { | @@ -202,7 +247,7 @@ public class SecurityContextImpl implements SecurityContext { | ||
| 202 | return bundle; | 247 | return bundle; |
| 203 | } | 248 | } |
| 204 | 249 | ||
| 205 | - private static class EmptyUser implements User{ | 250 | + private static class EmptyUser implements User { |
| 206 | 251 | ||
| 207 | private static final long serialVersionUID = 1L; | 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,4 +54,14 @@ public class AuthorizationException extends SecurityException { | ||
| 54 | public AuthorizationException(String message) { | 54 | public AuthorizationException(String message) { |
| 55 | super(message); | 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
| @@ -51,7 +51,6 @@ import org.junit.Test; | @@ -51,7 +51,6 @@ import org.junit.Test; | ||
| 51 | import org.junit.runner.RunWith; | 51 | import org.junit.runner.RunWith; |
| 52 | 52 | ||
| 53 | import test.Tests; | 53 | import test.Tests; |
| 54 | - | ||
| 55 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | 54 | import br.gov.frameworkdemoiselle.configuration.ConfigurationException; |
| 56 | 55 | ||
| 57 | @RunWith(Arquillian.class) | 56 | @RunWith(Arquillian.class) |
impl/core/src/test/java/management/testclasses/DummyManagementExtension.java
| @@ -40,7 +40,6 @@ import java.util.List; | @@ -40,7 +40,6 @@ import java.util.List; | ||
| 40 | 40 | ||
| 41 | import javax.inject.Inject; | 41 | import javax.inject.Inject; |
| 42 | 42 | ||
| 43 | - | ||
| 44 | import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; | 43 | import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; |
| 45 | import br.gov.frameworkdemoiselle.management.ManagementExtension; | 44 | import br.gov.frameworkdemoiselle.management.ManagementExtension; |
| 46 | 45 |
impl/core/src/test/java/security/athentication/ambiguity/DuplicatedCustomAuthenticator.java
| @@ -36,7 +36,6 @@ | @@ -36,7 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.ambiguity; | 37 | package security.athentication.ambiguity; |
| 38 | 38 | ||
| 39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 40 | import br.gov.frameworkdemoiselle.security.Authenticator; | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 41 | import br.gov.frameworkdemoiselle.security.User; | 40 | import br.gov.frameworkdemoiselle.security.User; |
| 42 | 41 | ||
| @@ -45,11 +44,11 @@ public class DuplicatedCustomAuthenticator implements Authenticator { | @@ -45,11 +44,11 @@ public class DuplicatedCustomAuthenticator implements Authenticator { | ||
| 45 | private static final long serialVersionUID = 1L; | 44 | private static final long serialVersionUID = 1L; |
| 46 | 45 | ||
| 47 | @Override | 46 | @Override |
| 48 | - public void authenticate() throws AuthenticationException { | 47 | + public void authenticate() { |
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | @Override | 50 | @Override |
| 52 | - public void unAuthenticate() { | 51 | + public void unauthenticate() { |
| 53 | } | 52 | } |
| 54 | 53 | ||
| 55 | @Override | 54 | @Override |
impl/core/src/test/java/security/athentication/credentials/StrictAuthenticator.java
| @@ -48,7 +48,7 @@ public class StrictAuthenticator implements Authenticator { | @@ -48,7 +48,7 @@ public class StrictAuthenticator implements Authenticator { | ||
| 48 | private User currentUser; | 48 | private User currentUser; |
| 49 | 49 | ||
| 50 | @Override | 50 | @Override |
| 51 | - public void authenticate() throws AuthenticationException { | 51 | + public void authenticate() { |
| 52 | 52 | ||
| 53 | Credentials c = Beans.getReference(Credentials.class); | 53 | Credentials c = Beans.getReference(Credentials.class); |
| 54 | if ("demoiselle".equals(c.getLogin())) { | 54 | if ("demoiselle".equals(c.getLogin())) { |
| @@ -75,7 +75,7 @@ public class StrictAuthenticator implements Authenticator { | @@ -75,7 +75,7 @@ public class StrictAuthenticator implements Authenticator { | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Override | 77 | @Override |
| 78 | - public void unAuthenticate() { | 78 | + public void unauthenticate() { |
| 79 | this.currentUser = null; | 79 | this.currentUser = null; |
| 80 | } | 80 | } |
| 81 | 81 |
impl/core/src/test/java/security/athentication/custom/CustomAuthenticator.java
| @@ -36,7 +36,6 @@ | @@ -36,7 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.custom; | 37 | package security.athentication.custom; |
| 38 | 38 | ||
| 39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 40 | import br.gov.frameworkdemoiselle.security.Authenticator; | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 41 | import br.gov.frameworkdemoiselle.security.User; | 40 | import br.gov.frameworkdemoiselle.security.User; |
| 42 | 41 | ||
| @@ -47,7 +46,7 @@ public class CustomAuthenticator implements Authenticator { | @@ -47,7 +46,7 @@ public class CustomAuthenticator implements Authenticator { | ||
| 47 | private User currentUser; | 46 | private User currentUser; |
| 48 | 47 | ||
| 49 | @Override | 48 | @Override |
| 50 | - public void authenticate() throws AuthenticationException { | 49 | + public void authenticate() { |
| 51 | this.currentUser = new User() { | 50 | this.currentUser = new User() { |
| 52 | 51 | ||
| 53 | private static final long serialVersionUID = 1L; | 52 | private static final long serialVersionUID = 1L; |
| @@ -68,7 +67,7 @@ public class CustomAuthenticator implements Authenticator { | @@ -68,7 +67,7 @@ public class CustomAuthenticator implements Authenticator { | ||
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | @Override | 69 | @Override |
| 71 | - public void unAuthenticate() { | 70 | + public void unauthenticate() { |
| 72 | this.currentUser = null; | 71 | this.currentUser = null; |
| 73 | } | 72 | } |
| 74 | 73 |
impl/core/src/test/java/security/athentication/error/ErrorAuthenticator.java
| @@ -36,7 +36,6 @@ | @@ -36,7 +36,6 @@ | ||
| 36 | */ | 36 | */ |
| 37 | package security.athentication.error; | 37 | package security.athentication.error; |
| 38 | 38 | ||
| 39 | -import br.gov.frameworkdemoiselle.security.AuthenticationException; | ||
| 40 | import br.gov.frameworkdemoiselle.security.Authenticator; | 39 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 41 | import br.gov.frameworkdemoiselle.security.User; | 40 | import br.gov.frameworkdemoiselle.security.User; |
| 42 | 41 | ||
| @@ -45,12 +44,12 @@ public class ErrorAuthenticator implements Authenticator { | @@ -45,12 +44,12 @@ public class ErrorAuthenticator implements Authenticator { | ||
| 45 | private static final long serialVersionUID = 1L; | 44 | private static final long serialVersionUID = 1L; |
| 46 | 45 | ||
| 47 | @Override | 46 | @Override |
| 48 | - public void authenticate() throws AuthenticationException { | 47 | + public void authenticate() { |
| 49 | throw new RuntimeException(); | 48 | throw new RuntimeException(); |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | @Override | 51 | @Override |
| 53 | - public void unAuthenticate() { | 52 | + public void unauthenticate() { |
| 54 | throw new RuntimeException(); | 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,11 +47,10 @@ import org.junit.Before; | ||
| 47 | import org.junit.Test; | 47 | import org.junit.Test; |
| 48 | import org.junit.runner.RunWith; | 48 | import org.junit.runner.RunWith; |
| 49 | 49 | ||
| 50 | +import test.Tests; | ||
| 50 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 51 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 51 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; | 52 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
| 52 | 53 | ||
| 53 | -import test.Tests; | ||
| 54 | - | ||
| 55 | @RunWith(Arquillian.class) | 54 | @RunWith(Arquillian.class) |
| 56 | public class TransactionWithCreatedStrategyTest { | 55 | public class TransactionWithCreatedStrategyTest { |
| 57 | 56 |
impl/core/src/test/java/transaction/defaultstrategy/TransactionDefaultTest.java
| @@ -45,12 +45,11 @@ import org.junit.Before; | @@ -45,12 +45,11 @@ import org.junit.Before; | ||
| 45 | import org.junit.Test; | 45 | import org.junit.Test; |
| 46 | import org.junit.runner.RunWith; | 46 | import org.junit.runner.RunWith; |
| 47 | 47 | ||
| 48 | +import test.Tests; | ||
| 48 | import br.gov.frameworkdemoiselle.DemoiselleException; | 49 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 49 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 50 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 50 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; | 51 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
| 51 | 52 | ||
| 52 | -import test.Tests; | ||
| 53 | - | ||
| 54 | @RunWith(Arquillian.class) | 53 | @RunWith(Arquillian.class) |
| 55 | public class TransactionDefaultTest { | 54 | public class TransactionDefaultTest { |
| 56 | 55 |
impl/core/src/test/java/util/beans/BeansTest.java
| @@ -48,7 +48,6 @@ import org.junit.Test; | @@ -48,7 +48,6 @@ import org.junit.Test; | ||
| 48 | import org.junit.runner.RunWith; | 48 | import org.junit.runner.RunWith; |
| 49 | 49 | ||
| 50 | import test.Tests; | 50 | import test.Tests; |
| 51 | - | ||
| 52 | import br.gov.frameworkdemoiselle.DemoiselleException; | 51 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 53 | import br.gov.frameworkdemoiselle.util.Beans; | 52 | import br.gov.frameworkdemoiselle.util.Beans; |
| 54 | 53 |
impl/core/src/test/java/util/beans/QualifierOne.java
| @@ -38,8 +38,8 @@ package util.beans; | @@ -38,8 +38,8 @@ package util.beans; | ||
| 38 | 38 | ||
| 39 | import static java.lang.annotation.ElementType.FIELD; | 39 | import static java.lang.annotation.ElementType.FIELD; |
| 40 | import static java.lang.annotation.ElementType.METHOD; | 40 | import static java.lang.annotation.ElementType.METHOD; |
| 41 | -import static java.lang.annotation.ElementType.TYPE; | ||
| 42 | import static java.lang.annotation.ElementType.PARAMETER; | 41 | import static java.lang.annotation.ElementType.PARAMETER; |
| 42 | +import static java.lang.annotation.ElementType.TYPE; | ||
| 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; | 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
| 44 | 44 | ||
| 45 | import java.lang.annotation.Retention; | 45 | import java.lang.annotation.Retention; |
impl/core/src/test/java/util/beans/QualifierTwo.java
| @@ -38,8 +38,8 @@ package util.beans; | @@ -38,8 +38,8 @@ package util.beans; | ||
| 38 | 38 | ||
| 39 | import static java.lang.annotation.ElementType.FIELD; | 39 | import static java.lang.annotation.ElementType.FIELD; |
| 40 | import static java.lang.annotation.ElementType.METHOD; | 40 | import static java.lang.annotation.ElementType.METHOD; |
| 41 | -import static java.lang.annotation.ElementType.TYPE; | ||
| 42 | import static java.lang.annotation.ElementType.PARAMETER; | 41 | import static java.lang.annotation.ElementType.PARAMETER; |
| 42 | +import static java.lang.annotation.ElementType.TYPE; | ||
| 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; | 43 | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
| 44 | 44 | ||
| 45 | import java.lang.annotation.Retention; | 45 | import java.lang.annotation.Retention; |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/security/ServletAuthenticator.java
| @@ -74,7 +74,7 @@ public class ServletAuthenticator implements Authenticator { | @@ -74,7 +74,7 @@ public class ServletAuthenticator implements Authenticator { | ||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | @Override | 76 | @Override |
| 77 | - public void unAuthenticate() { | 77 | + public void unauthenticate() { |
| 78 | getCredentials().clear(); | 78 | getCredentials().clear(); |
| 79 | try { | 79 | try { |
| 80 | getRequest().logout(); | 80 | getRequest().logout(); |