Search in sources :

Example 1 with BeanResourceNameFactory

use of io.vertigo.persona.impl.security.BeanResourceNameFactory in project vertigo by KleeGroup.

the class VSecurityManagerTest method testAuthorizedAllWithResourceNameFactory.

@Test
public void testAuthorizedAllWithResourceNameFactory() {
    securityManager.registerResourceNameFactory(Famille.class.getSimpleName(), new BeanResourceNameFactory("/famille/${famId}"));
    final Famille famille12 = new Famille();
    famille12.setFamId(12L);
    final Famille famille13 = new Famille();
    famille13.setFamId(13L);
    // Test toutes familles
    final Role readAllFamillies = getRole("R_ALL_FAMILLES");
    final UserSession userSession = securityManager.<PersonaUserSession>createUserSession().addRole(readAllFamillies);
    try {
        securityManager.startCurrentUserSession(userSession);
        final boolean canRead12 = securityManager.isAuthorized(Famille.class.getSimpleName(), famille12, "READ");
        Assert.assertTrue(canRead12);
        final boolean canRead13 = securityManager.isAuthorized(Famille.class.getSimpleName(), famille13, "READ");
        Assert.assertTrue(canRead13);
    } finally {
        securityManager.stopCurrentUserSession();
    }
}
Also used : Role(io.vertigo.persona.security.metamodel.Role) BeanResourceNameFactory(io.vertigo.persona.impl.security.BeanResourceNameFactory) Test(org.junit.Test)

Example 2 with BeanResourceNameFactory

use of io.vertigo.persona.impl.security.BeanResourceNameFactory in project vertigo by KleeGroup.

the class VSecurityManagerTest method testAuthorizedSessionPropertyWithResourceNameFactory.

@Test
public void testAuthorizedSessionPropertyWithResourceNameFactory() {
    securityManager.registerResourceNameFactory(Famille.class.getSimpleName(), new BeanResourceNameFactory("/famille/${famId}"));
    final Famille famille12 = new Famille();
    famille12.setFamId(12L);
    final Famille famille13 = new Famille();
    famille13.setFamId(13L);
    // Test ma famille
    final Role readMyFamilly = getRole("R_MY_FAMILLE");
    final UserSession userSession = securityManager.<TestUserSession>createUserSession().withSecurityKeys("famId", String.valueOf(famille12.id)).addRole(readMyFamilly);
    try {
        securityManager.startCurrentUserSession(userSession);
        final boolean canRead12 = securityManager.isAuthorized(Famille.class.getSimpleName(), famille12, "READ");
        Assert.assertTrue(canRead12);
        final boolean canRead13 = securityManager.isAuthorized(Famille.class.getSimpleName(), famille13, "READ");
        Assert.assertFalse(canRead13);
    } finally {
        securityManager.stopCurrentUserSession();
    }
}
Also used : Role(io.vertigo.persona.security.metamodel.Role) BeanResourceNameFactory(io.vertigo.persona.impl.security.BeanResourceNameFactory) Test(org.junit.Test)

Aggregations

BeanResourceNameFactory (io.vertigo.persona.impl.security.BeanResourceNameFactory)2 Role (io.vertigo.persona.security.metamodel.Role)2 Test (org.junit.Test)2