Commit d6266d0c93298c3c044af02d36cd5ae12e227a78
1 parent
a9efdea1
Exists in
master
Correção nos testes para aderir à nova especificação das interfaces de
segurança.
Showing
3 changed files
with
44 additions
and
61 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
| ... | ... | @@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | 39 | import javax.inject.Named; |
| 40 | 40 | |
| 41 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 41 | 42 | import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; |
| 42 | 43 | import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; |
| 43 | 44 | import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; |
| ... | ... | @@ -45,7 +46,6 @@ import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 45 | 46 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 46 | 47 | import br.gov.frameworkdemoiselle.security.AuthorizationException; |
| 47 | 48 | import br.gov.frameworkdemoiselle.security.Authorizer; |
| 48 | -import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | |
| 49 | 49 | import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
| 50 | 50 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 51 | 51 | import br.gov.frameworkdemoiselle.security.User; |
| ... | ... | @@ -110,7 +110,7 @@ public class SecurityContextImpl implements SecurityContext { |
| 110 | 110 | try { |
| 111 | 111 | result = getAuthorizer().hasPermission(resource, operation); |
| 112 | 112 | |
| 113 | - } catch (AuthorizationException cause) { | |
| 113 | + } catch (DemoiselleException cause) { | |
| 114 | 114 | throw cause; |
| 115 | 115 | |
| 116 | 116 | } catch (Exception cause) { |
| ... | ... | @@ -134,7 +134,7 @@ public class SecurityContextImpl implements SecurityContext { |
| 134 | 134 | try { |
| 135 | 135 | result = getAuthorizer().hasRole(role); |
| 136 | 136 | |
| 137 | - } catch (AuthorizationException cause) { | |
| 137 | + } catch (DemoiselleException cause) { | |
| 138 | 138 | throw cause; |
| 139 | 139 | |
| 140 | 140 | } catch (Exception cause) { |
| ... | ... | @@ -169,10 +169,7 @@ public class SecurityContextImpl implements SecurityContext { |
| 169 | 169 | try { |
| 170 | 170 | getAuthenticator().authenticate(); |
| 171 | 171 | |
| 172 | - } catch (InvalidCredentialsException cause) { | |
| 173 | - throw cause; | |
| 174 | - | |
| 175 | - } catch (AuthenticationException cause) { | |
| 172 | + } catch (DemoiselleException cause) { | |
| 176 | 173 | throw cause; |
| 177 | 174 | |
| 178 | 175 | } catch (Exception cause) { |
| ... | ... | @@ -198,10 +195,7 @@ public class SecurityContextImpl implements SecurityContext { |
| 198 | 195 | try { |
| 199 | 196 | getAuthenticator().unauthenticate(); |
| 200 | 197 | |
| 201 | - } catch (InvalidCredentialsException cause) { | |
| 202 | - throw cause; | |
| 203 | - | |
| 204 | - } catch (AuthenticationException cause) { | |
| 198 | + } catch (DemoiselleException cause) { | |
| 205 | 199 | throw cause; |
| 206 | 200 | |
| 207 | 201 | } catch (Exception cause) { | ... | ... |
impl/core/src/test/java/security/athentication/error/ErrorAuthenticatorTest.java
| ... | ... | @@ -36,9 +36,10 @@ |
| 36 | 36 | */ |
| 37 | 37 | package security.athentication.error; |
| 38 | 38 | |
| 39 | -import javax.inject.Inject; | |
| 39 | +import static junit.framework.Assert.assertEquals; | |
| 40 | +import static junit.framework.Assert.fail; | |
| 40 | 41 | |
| 41 | -import junit.framework.Assert; | |
| 42 | +import javax.inject.Inject; | |
| 42 | 43 | |
| 43 | 44 | import org.jboss.arquillian.container.test.api.Deployment; |
| 44 | 45 | import org.jboss.arquillian.junit.Arquillian; |
| ... | ... | @@ -63,33 +64,27 @@ public class ErrorAuthenticatorTest { |
| 63 | 64 | deployment.addClass(ErrorAuthenticator.class); |
| 64 | 65 | return deployment; |
| 65 | 66 | } |
| 66 | - | |
| 67 | + | |
| 67 | 68 | @Test |
| 68 | - public void errorDuringLogin(){ | |
| 69 | - try{ | |
| 69 | + public void errorDuringLogin() { | |
| 70 | + try { | |
| 70 | 71 | context.login(); |
| 71 | - Assert.fail("Login deveria disparar exceção de runtime"); | |
| 72 | - } | |
| 73 | - catch(AuthenticationException ae){ | |
| 74 | - Assert.fail("A exceção disparada não foi a esperada"); | |
| 75 | - } | |
| 76 | - catch(RuntimeException e){ | |
| 77 | - //PASS | |
| 72 | + fail("Login deveria disparar exceção de runtime"); | |
| 73 | + | |
| 74 | + } catch (AuthenticationException cause) { | |
| 75 | + assertEquals(RuntimeException.class, cause.getCause().getClass()); | |
| 78 | 76 | } |
| 79 | 77 | } |
| 80 | - | |
| 78 | + | |
| 81 | 79 | @Test |
| 82 | - public void errorDuringLogout(){ | |
| 83 | - try{ | |
| 80 | + public void errorDuringLogout() { | |
| 81 | + try { | |
| 84 | 82 | context.login(); |
| 85 | - Assert.fail("Logout deveria disparar exceção de runtime"); | |
| 86 | - } | |
| 87 | - catch(AuthenticationException ae){ | |
| 88 | - Assert.fail("A exceção disparada não foi a esperada"); | |
| 89 | - } | |
| 90 | - catch(RuntimeException e){ | |
| 91 | - //PASS | |
| 83 | + fail("Logout deveria disparar exceção de runtime"); | |
| 84 | + | |
| 85 | + } catch (AuthenticationException cause) { | |
| 86 | + assertEquals(RuntimeException.class, cause.getCause().getClass()); | |
| 92 | 87 | } |
| 93 | 88 | } |
| 94 | - | |
| 89 | + | |
| 95 | 90 | } | ... | ... |
impl/core/src/test/java/security/authorization/error/ErrorAuthorizerTest.java
| ... | ... | @@ -36,9 +36,10 @@ |
| 36 | 36 | */ |
| 37 | 37 | package security.authorization.error; |
| 38 | 38 | |
| 39 | -import javax.inject.Inject; | |
| 39 | +import static junit.framework.Assert.assertEquals; | |
| 40 | +import static junit.framework.Assert.fail; | |
| 40 | 41 | |
| 41 | -import junit.framework.Assert; | |
| 42 | +import javax.inject.Inject; | |
| 42 | 43 | |
| 43 | 44 | import org.jboss.arquillian.container.test.api.Deployment; |
| 44 | 45 | import org.jboss.arquillian.junit.Arquillian; |
| ... | ... | @@ -51,7 +52,6 @@ import org.junit.runner.RunWith; |
| 51 | 52 | import security.athentication.custom.CustomAuthenticator; |
| 52 | 53 | import test.Tests; |
| 53 | 54 | import br.gov.frameworkdemoiselle.security.AuthorizationException; |
| 54 | -import br.gov.frameworkdemoiselle.security.NotLoggedInException; | |
| 55 | 55 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 56 | 56 | import configuration.resource.ConfigurationResourceTest; |
| 57 | 57 | |
| ... | ... | @@ -68,43 +68,37 @@ public class ErrorAuthorizerTest { |
| 68 | 68 | deployment.addClass(ErrorAuthorizer.class); |
| 69 | 69 | return deployment; |
| 70 | 70 | } |
| 71 | - | |
| 71 | + | |
| 72 | 72 | @Before |
| 73 | - public void loginToTest(){ | |
| 73 | + public void loginToTest() { | |
| 74 | 74 | context.login(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | @Test |
| 78 | - public void errorDuringCheckPermission(){ | |
| 79 | - try{ | |
| 78 | + public void errorDuringCheckPermission() { | |
| 79 | + try { | |
| 80 | 80 | context.hasPermission("resource", "operation"); |
| 81 | - Assert.fail("Verificar permissão deveria disparar exceção de runtime"); | |
| 82 | - } | |
| 83 | - catch(NotLoggedInException ae){ | |
| 84 | - Assert.fail("A exceção disparada não foi a esperada"); | |
| 85 | - } | |
| 86 | - catch(RuntimeException e){ | |
| 87 | - //PASS | |
| 81 | + fail("Verificar permissão deveria disparar exceção de runtime"); | |
| 82 | + | |
| 83 | + } catch (AuthorizationException cause) { | |
| 84 | + assertEquals(RuntimeException.class, cause.getCause().getClass()); | |
| 88 | 85 | } |
| 89 | 86 | } |
| 90 | - | |
| 87 | + | |
| 91 | 88 | @Test |
| 92 | - public void errorDuringCheckRole(){ | |
| 93 | - try{ | |
| 89 | + public void errorDuringCheckRole() { | |
| 90 | + try { | |
| 94 | 91 | context.hasRole("role"); |
| 95 | - Assert.fail("Verificar papel deveria disparar exceção de runtime"); | |
| 96 | - } | |
| 97 | - catch(AuthorizationException ae){ | |
| 98 | - Assert.fail("A exceção disparada não foi a esperada"); | |
| 99 | - } | |
| 100 | - catch(RuntimeException e){ | |
| 101 | - //PASS | |
| 92 | + fail("Verificar papel deveria disparar exceção de runtime"); | |
| 93 | + | |
| 94 | + } catch (AuthorizationException cause) { | |
| 95 | + assertEquals(RuntimeException.class, cause.getCause().getClass()); | |
| 102 | 96 | } |
| 103 | 97 | } |
| 104 | - | |
| 98 | + | |
| 105 | 99 | @After |
| 106 | - public void logoutAfterTest(){ | |
| 100 | + public void logoutAfterTest() { | |
| 107 | 101 | context.logout(); |
| 108 | 102 | } |
| 109 | - | |
| 103 | + | |
| 110 | 104 | } | ... | ... |