Search in sources :

Example 1 with Role

use of org.picketlink.idm.model.basic.Role in project wildfly by wildfly.

the class AbstractBasicIdentityManagementTestCase method testRelationshipManagement.

@Test
@InSequence(5)
public void testRelationshipManagement() throws Exception {
    PartitionManager partitionManager = getPartitionManager();
    IdentityManager identityManager = partitionManager.createIdentityManager();
    User user = getUser(identityManager, "johny");
    Role role = getRole(identityManager, "admin");
    RelationshipManager relationshipManager = partitionManager.createRelationshipManager();
    BasicModel.grantRole(relationshipManager, user, role);
    assertTrue(hasRole(relationshipManager, user, role));
}
Also used : BasicModel.hasRole(org.picketlink.idm.model.basic.BasicModel.hasRole) Role(org.picketlink.idm.model.basic.Role) BasicModel.getRole(org.picketlink.idm.model.basic.BasicModel.getRole) IdentityManager(org.picketlink.idm.IdentityManager) User(org.picketlink.idm.model.basic.User) BasicModel.getUser(org.picketlink.idm.model.basic.BasicModel.getUser) PartitionManager(org.picketlink.idm.PartitionManager) RelationshipManager(org.picketlink.idm.RelationshipManager) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with Role

use of org.picketlink.idm.model.basic.Role in project wildfly by wildfly.

the class MultipleIdentityStoreConfigurationTestCase method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    Realm defaultRealm = this.partitionManager.getPartition(Realm.class, Realm.DEFAULT_REALM);
    if (defaultRealm == null) {
        defaultRealm = new Realm(Realm.DEFAULT_REALM);
        this.partitionManager.add(defaultRealm);
    }
    IdentityManager identityManager = this.partitionManager.createIdentityManager();
    User user = new User("mary");
    identityManager.add(user);
    assertNotNull(BasicModel.getUser(identityManager, user.getLoginName()));
    Password password = new Password("abcd1234");
    identityManager.updateCredential(user, password);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user.getLoginName(), password);
    identityManager.validateCredentials(credentials);
    assertEquals(Credentials.Status.VALID, credentials.getStatus());
    Role role = new Role("ruler");
    identityManager.add(role);
    assertNotNull(BasicModel.getRole(identityManager, role.getName()));
}
Also used : Role(org.picketlink.idm.model.basic.Role) IdentityManager(org.picketlink.idm.IdentityManager) User(org.picketlink.idm.model.basic.User) Realm(org.picketlink.idm.model.basic.Realm) Password(org.picketlink.idm.credential.Password) UsernamePasswordCredentials(org.picketlink.idm.credential.UsernamePasswordCredentials) Test(org.junit.Test)

Example 3 with Role

use of org.picketlink.idm.model.basic.Role in project wildfly by wildfly.

the class PartitionManagerProducerTestCase method testAuthentication.

@Test
@InSequence(2)
public void testAuthentication() {
    User user = new User("johny");
    this.identityManager.add(user);
    Password password = new Password("abcd1234");
    this.identityManager.updateCredential(user, password);
    Role role = new Role("admin");
    this.identityManager.add(role);
    BasicModel.grantRole(this.relationshipManager, user, role);
    this.credentials.setUserId("johny");
    this.credentials.setPassword("abcd1234");
    this.identity.login();
    assertTrue(this.identity.isLoggedIn());
    user = BasicModel.getUser(this.identityManager, "johny");
    role = BasicModel.getRole(this.identityManager, "admin");
    assertTrue(BasicModel.hasRole(this.relationshipManager, user, role));
}
Also used : Role(org.picketlink.idm.model.basic.Role) User(org.picketlink.idm.model.basic.User) Password(org.picketlink.idm.credential.Password) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with Role

use of org.picketlink.idm.model.basic.Role in project wildfly by wildfly.

the class AbstractBasicIdentityManagementTestCase method testRoleManagement.

@Test
@InSequence(4)
public void testRoleManagement() throws Exception {
    PartitionManager partitionManager = getPartitionManager();
    IdentityManager identityManager = partitionManager.createIdentityManager();
    String roleName = "admin";
    Role role = getRole(identityManager, roleName);
    if (role != null) {
        identityManager.remove(role);
    }
    identityManager.add(new Role(roleName));
    assertNotNull(getRole(identityManager, roleName));
}
Also used : BasicModel.hasRole(org.picketlink.idm.model.basic.BasicModel.hasRole) Role(org.picketlink.idm.model.basic.Role) BasicModel.getRole(org.picketlink.idm.model.basic.BasicModel.getRole) IdentityManager(org.picketlink.idm.IdentityManager) PartitionManager(org.picketlink.idm.PartitionManager) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 5 with Role

use of org.picketlink.idm.model.basic.Role in project wildfly by wildfly.

the class MultipleIdentityConfigurationTestCase method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    Realm defaultRealm = this.partitionManager.getPartition(Realm.class, Realm.DEFAULT_REALM);
    if (defaultRealm == null) {
        defaultRealm = new Realm(Realm.DEFAULT_REALM);
        this.partitionManager.add(defaultRealm);
    }
    IdentityManager identityManager = this.partitionManager.createIdentityManager();
    User user = new User("mary");
    identityManager.add(user);
    assertNotNull(BasicModel.getUser(identityManager, user.getLoginName()));
    Password password = new Password("abcd1234");
    identityManager.updateCredential(user, password);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user.getLoginName(), password);
    identityManager.validateCredentials(credentials);
    assertEquals(Credentials.Status.VALID, credentials.getStatus());
    Role role = new Role("ruler");
    identityManager.add(role);
    assertNotNull(BasicModel.getRole(identityManager, role.getName()));
}
Also used : Role(org.picketlink.idm.model.basic.Role) IdentityManager(org.picketlink.idm.IdentityManager) User(org.picketlink.idm.model.basic.User) Realm(org.picketlink.idm.model.basic.Realm) Password(org.picketlink.idm.credential.Password) UsernamePasswordCredentials(org.picketlink.idm.credential.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Role (org.picketlink.idm.model.basic.Role)5 IdentityManager (org.picketlink.idm.IdentityManager)4 User (org.picketlink.idm.model.basic.User)4 InSequence (org.jboss.arquillian.junit.InSequence)3 Password (org.picketlink.idm.credential.Password)3 PartitionManager (org.picketlink.idm.PartitionManager)2 UsernamePasswordCredentials (org.picketlink.idm.credential.UsernamePasswordCredentials)2 BasicModel.getRole (org.picketlink.idm.model.basic.BasicModel.getRole)2 BasicModel.hasRole (org.picketlink.idm.model.basic.BasicModel.hasRole)2 Realm (org.picketlink.idm.model.basic.Realm)2 RelationshipManager (org.picketlink.idm.RelationshipManager)1 BasicModel.getUser (org.picketlink.idm.model.basic.BasicModel.getUser)1