Java Code Examples for org.wildfly.security.auth.server.SecurityRealm#getRealmIdentity()

The following examples show how to use org.wildfly.security.auth.server.SecurityRealm#getRealmIdentity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RealmsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testPropertyRealm() throws Exception {
    KernelServices services = super.createKernelServicesBuilder(new TestEnvironment()).setSubsystemXmlResource("realms-test.xml").build();
    if (!services.isSuccessfulBoot()) {
        Assert.fail(services.getBootError().toString());
    }

    ServiceName serviceName = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("HashedPropertyRealm");
    SecurityRealm securityRealm = (SecurityRealm) services.getContainer().getService(serviceName).getValue();
    testAbstractPropertyRealm(securityRealm);

    ServiceName serviceName2 = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("ClearPropertyRealm");
    SecurityRealm securityRealm2 = (SecurityRealm) services.getContainer().getService(serviceName2).getValue();
    testAbstractPropertyRealm(securityRealm2);

    RealmIdentity identity1 = securityRealm2.getRealmIdentity(fromName("user1"));
    Object[] groups = identity1.getAuthorizationIdentity().getAttributes().get("groupAttr").toArray();
    Assert.assertArrayEquals(new Object[]{"firstGroup","secondGroup"}, groups);
}
 
Example 2
Source File: RealmsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void testAbstractPropertyRealm(SecurityRealm securityRealm) throws Exception {
    Assert.assertNotNull(securityRealm);

    RealmIdentity identity1 = securityRealm.getRealmIdentity(fromName("user1"));
    Assert.assertTrue(identity1.exists());
    Assert.assertTrue(identity1.verifyEvidence(new PasswordGuessEvidence("password1".toCharArray())));
    Assert.assertFalse(identity1.verifyEvidence(new PasswordGuessEvidence("password2".toCharArray())));
    identity1.dispose();

    RealmIdentity identity2 = securityRealm.getRealmIdentity(fromName("user2"));
    Assert.assertTrue(identity2.exists());
    Assert.assertTrue(identity2.verifyEvidence(new PasswordGuessEvidence("password2".toCharArray())));
    identity2.dispose();

    RealmIdentity identity9 = securityRealm.getRealmIdentity(fromName("user9"));
    Assert.assertFalse(identity9.exists());
    Assert.assertFalse(identity9.verifyEvidence(new PasswordGuessEvidence("password9".toCharArray())));
    identity9.dispose();
}
 
Example 3
Source File: RealmsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testAggregateRealm() throws Exception {
    KernelServices services = super.createKernelServicesBuilder(new TestEnvironment()).setSubsystemXmlResource("realms-test.xml").build();
    if (!services.isSuccessfulBoot()) {
        Assert.fail(services.getBootError().toString());
    }

    ServiceName serviceName = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("AggregateRealmOne");
    SecurityRealm securityRealm = (SecurityRealm) services.getContainer().getService(serviceName).getValue();
    Assert.assertNotNull(securityRealm);

    RealmIdentity identity1 = securityRealm.getRealmIdentity(fromName("firstUser"));
    Assert.assertTrue(identity1.exists());

    Assert.assertEquals(3, identity1.getAuthorizationIdentity().getAttributes().size());
    Assert.assertEquals("[Jane]", identity1.getAuthorizationIdentity().getAttributes().get("firstName").toString());
    Assert.assertEquals("[Doe]", identity1.getAuthorizationIdentity().getAttributes().get("lastName").toString());
    Assert.assertEquals("[Employee, Manager, Admin]", identity1.getAuthorizationIdentity().getAttributes().get("roles").toString());

    identity1.dispose();
}
 
Example 4
Source File: RealmsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testAggregateRealmWithPrincipalTransformer() throws Exception {
    KernelServices services = super.createKernelServicesBuilder(new TestEnvironment()).setSubsystemXmlResource("realms-test.xml").build();
    if (!services.isSuccessfulBoot()) {
        Assert.fail(services.getBootError().toString());
    }

    ServiceName serviceName = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("AggregateRealmTwo");
    SecurityRealm securityRealm = (SecurityRealm) services.getContainer().getService(serviceName).getValue();
    Assert.assertNotNull(securityRealm);

    RealmIdentity identity1 = securityRealm.getRealmIdentity(fromName("firstUser"));
    Assert.assertTrue(identity1.exists());
    //Assert that transformation was successful and the correct identity and attributes were loaded from filesystem-realm-2
    Assert.assertEquals(3, identity1.getAuthorizationIdentity().getAttributes().size());
    Assert.assertEquals("[Jane2]", identity1.getAuthorizationIdentity().getAttributes().get("firstName").toString());
    Assert.assertEquals("[Doe2]", identity1.getAuthorizationIdentity().getAttributes().get("lastName").toString());
    Assert.assertEquals("[Employee2, Manager2, Admin2]", identity1.getAuthorizationIdentity().getAttributes().get("roles").toString());

    identity1.dispose();
}