use of io.vertigo.persona.security.UserSession in project vertigo by KleeGroup.
the class VSecurityManagerTest method testInitCurrentUserSession.
@Test
public void testInitCurrentUserSession() {
final UserSession userSession = securityManager.createUserSession();
try {
securityManager.startCurrentUserSession(userSession);
Assert.assertTrue(securityManager.getCurrentUserSession().isPresent());
Assert.assertEquals(userSession, securityManager.getCurrentUserSession().get());
} finally {
securityManager.stopCurrentUserSession();
}
}
use of io.vertigo.persona.security.UserSession in project vertigo by KleeGroup.
the class VSecurityManagerTest method testSecuritySearchOnEntity.
@Test
public void testSecuritySearchOnEntity() {
final Record recordTooExpensive = createRecord();
recordTooExpensive.setAmount(10000d);
final Record recordOtherUser = createRecord();
recordOtherUser.setUtiIdOwner(2000L);
final Record recordOtherUserAndTooExpensive = createRecord();
recordOtherUserAndTooExpensive.setUtiIdOwner(2000L);
recordOtherUserAndTooExpensive.setAmount(10000d);
final Authorization recordRead = getAuthorization(RecordAuthorizations.ATZ_RECORD$READ);
final UserSession userSession = securityManager.<TestUserSession>createUserSession();
try {
securityManager.startCurrentUserSession(userSession);
authorizationManager.obtainUserAuthorizations().withSecurityKeys("utiId", DEFAULT_UTI_ID).withSecurityKeys("typId", DEFAULT_TYPE_ID).withSecurityKeys("montantMax", DEFAULT_MONTANT_MAX).addAuthorization(recordRead).addAuthorization(getAuthorization(RecordAuthorizations.ATZ_RECORD$READ_HP)).addAuthorization(getAuthorization(RecordAuthorizations.ATZ_RECORD$WRITE)).addAuthorization(getAuthorization(RecordAuthorizations.ATZ_RECORD$CREATE)).addAuthorization(getAuthorization(RecordAuthorizations.ATZ_RECORD$DELETE));
final boolean canReadRecord = authorizationManager.hasAuthorization(RecordAuthorizations.ATZ_RECORD$READ);
Assert.assertTrue(canReadRecord);
// read -> MONTANT<=${montantMax} or UTI_ID_OWNER=${utiId}
Assert.assertEquals("(+AMOUNT:<=100.0) (+UTI_ID_OWNER:1000)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.READ));
Assert.assertEquals("(AMOUNT:<=100.0 UTI_ID_OWNER:1000)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.READ2));
Assert.assertEquals("(*:*)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.READ_HP));
Assert.assertEquals("(+UTI_ID_OWNER:1000 +ETA_CD:<ARC) (+TYP_ID:10 +AMOUNT:<=100.0 +ETA_CD:<ARC)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.WRITE));
Assert.assertEquals("(+TYP_ID:10 +AMOUNT:<=100.0)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.CREATE));
Assert.assertEquals("(+TYP_ID:10) (+UTI_ID_OWNER:1000 +ETA_CD:<PUB)", authorizationManager.getSearchSecurity(Record.class, RecordOperations.DELETE));
final boolean canReadNotify = authorizationManager.hasAuthorization(RecordAuthorizations.ATZ_RECORD$NOTIFY);
Assert.assertFalse(canReadNotify);
Assert.assertEquals("", authorizationManager.getSearchSecurity(Record.class, RecordOperations.NOTIFY));
} finally {
securityManager.stopCurrentUserSession();
}
}
use of io.vertigo.persona.security.UserSession in project vertigo by KleeGroup.
the class AuthenticationManagerTest method loginSuccess.
private Optional<Account> loginSuccess() {
final AuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "v3rt1g0");
final Optional<Account> account = authenticationManager.login(token);
Assert.assertTrue("Authent fail", account.isPresent());
final Optional<UserSession> userSession = securityManager.getCurrentUserSession();
Assert.assertTrue("No UserSession", userSession.isPresent());
Assert.assertTrue("Not authenticated", userSession.get().isAuthenticated());
return account;
}
use of io.vertigo.persona.security.UserSession in project vertigo by KleeGroup.
the class VSecurityManagerTest method testAuthenticate.
public void testAuthenticate() {
final UserSession userSession = securityManager.createUserSession();
Assert.assertFalse(userSession.isAuthenticated());
userSession.authenticate();
}
use of io.vertigo.persona.security.UserSession in project vertigo by KleeGroup.
the class VSecurityManagerTest method testResetUserSession.
@Test
public void testResetUserSession() {
final UserSession userSession = securityManager.createUserSession();
try {
securityManager.startCurrentUserSession(userSession);
Assert.assertTrue(securityManager.getCurrentUserSession().isPresent());
//
authorizationManager.obtainUserAuthorizations().clearSecurityKeys();
authorizationManager.obtainUserAuthorizations().clearAuthorizations();
authorizationManager.obtainUserAuthorizations().clearRoles();
} finally {
securityManager.stopCurrentUserSession();
}
Assert.assertFalse(securityManager.getCurrentUserSession().isPresent());
}
Aggregations