Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

seam security create group and add user to group

View gist:1321262
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
@Inject
private IdentitySession identitySession;
 
@Inject
private Identity identity;
 
@Inject
private UserTransaction tx;
 
@Before
public void setupTestUser() throws IdentityException, FeatureNotSupportedException, SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException {
final PersistenceManager pm = identitySession.getPersistenceManager();
final AttributesManager am = identitySession.getAttributesManager();
final RelationshipManager rm = identitySession.getRelationshipManager();
 
// Group creation must be done in a separate transaction so it's flushed to the DB before adding members to that group
tx.begin();
// Setup the group we want our user to belong to
final Group memberGroup = pm.createGroup("member", "USER");
final User user = pm.createUser("test");
 
am.updatePassword(user, "password");
tx.commit();
 
// Now we can go ahead and create the association
tx.begin();
rm.associateUser(memberGroup, user);
tx.commit();
}
 
@Test
public void assertUserCanAuthenticate(Credentials credentials) {
credentials.setUsername("test");
credentials.setCredential(new PasswordCredential("password"));
assertThat(identity.login(), is(Identity.RESPONSE_LOGIN_SUCCESS));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.