Created
November 28, 2013 16:00
-
-
Save flaviocdc/7694130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java | |
=================================================================== | |
--- src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java (revision 3079) | |
+++ src/test/br/ufrj/gnosys/framework/mock/FakeLogin.java (working copy) | |
@@ -1,15 +1,23 @@ | |
package br.ufrj.gnosys.framework.mock; | |
+import java.util.HashSet; | |
+ | |
+import javax.persistence.EntityManager; | |
+ | |
import org.jboss.seam.Component; | |
import org.jboss.seam.annotations.AutoCreate; | |
import org.jboss.seam.annotations.In; | |
import org.jboss.seam.annotations.Name; | |
+import org.jboss.seam.contexts.Contexts; | |
import org.jboss.seam.core.Expressions; | |
import org.jboss.seam.security.Credentials; | |
import org.jboss.seam.security.Identity; | |
+import br.ufrj.gnosys.framework.system.Opcao; | |
import br.ufrj.gnosys.framework.system.Perfil; | |
+import br.ufrj.gnosys.framework.system.Usuario; | |
import br.ufrj.gnosys.security.GnosysPrincipal; | |
+import br.ufrj.gnosys.security.GnosysToken; | |
@Name("fakeLogin") | |
@AutoCreate | |
@@ -18,21 +26,25 @@ | |
@In | |
private Credentials credentials; | |
+ | |
@In | |
private Identity identity; | |
- public void login(String username, String... perfis) | |
+ @In | |
+ private EntityManager entityManager; | |
+ | |
+ public void login(String identificacaoUFRJ) | |
{ | |
- credentials.setUsername(username); | |
- credentials.setPassword(username); | |
+ Usuario usuario = recuperarUsuario(identificacaoUFRJ); | |
+ | |
+ credentials.setUsername(identificacaoUFRJ); | |
+ credentials.setPassword(identificacaoUFRJ); | |
identity.setAuthenticateMethod(Expressions.instance().createMethodExpression("#{fakeLogin.authenticate}")); | |
identity.login(); | |
- for (String perfil : perfis) | |
- { | |
- identity.addRole(perfil); | |
- } | |
+ GnosysPrincipal principal = new GnosysPrincipal(usuario, new HashSet<Opcao>(), new GnosysToken()); | |
+ Contexts.getSessionContext().set("currentUserPrincipal", principal); | |
} | |
@@ -47,4 +59,11 @@ | |
return true; | |
} | |
+ | |
+ public Usuario recuperarUsuario(String identificacaoUFRJ) | |
+ { | |
+ return (Usuario) entityManager.createNamedQuery("qryRecuperarUsuarioPorIdentificacaoUFRJ") | |
+ .setParameter("identificacaoUFRJ", identificacaoUFRJ) | |
+ .getSingleResult(); | |
+ } | |
} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment