Search in sources :

Example 6 with Account

use of io.vertigo.account.account.Account in project vertigo by KleeGroup.

the class MemoryAccountCachePlugin method putAccount.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void putAccount(final Account account) {
    Assertion.checkNotNull(account);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(account);
    final URI<Account> uri = new URI<>(dtDefinition, account.getId());
    // ----
    final Object old = accountByURI.put(uri, account);
    if (old == null) {
        groupByAccountURI.put(uri, new HashSet<URI<AccountGroup>>());
        accountURIByAuthToken.put(account.getAuthToken(), uri);
    }
}
Also used : Account(io.vertigo.account.account.Account) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI)

Example 7 with Account

use of io.vertigo.account.account.Account in project vertigo by KleeGroup.

the class RedisAccountCachePlugin method getAccountURIs.

/**
 * {@inheritDoc}
 */
@Override
public Set<URI<Account>> getAccountURIs(final URI<AccountGroup> groupURI) {
    Assertion.checkNotNull(groupURI);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(Account.class);
    final Set<URI<Account>> set = new HashSet<>();
    try (final Jedis jedis = redisConnector.getResource()) {
        final Set<String> ids = jedis.smembers(SACCOUNTS_BY_GROUP_START_KEY + groupURI.getId());
        for (final String id : ids) {
            set.add(new URI<Account>(dtDefinition, id));
        }
        return set;
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Account(io.vertigo.account.account.Account) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) HashSet(java.util.HashSet)

Example 8 with Account

use of io.vertigo.account.account.Account in project vertigo by KleeGroup.

the class StoreAccountStorePlugin method getGroupURIs.

/**
 * {@inheritDoc}
 */
@Override
public Set<URI<AccountGroup>> getGroupURIs(final URI<Account> accountURI) {
    if (associationUserGroup instanceof AssociationSimpleDefinition) {
        // case 1 group per user
        final URI<Entity> userURI = new URI(getUserDtDefinition(), accountURI.getId());
        final Entity userEntity = storeManager.getDataStore().readOne(userURI);
        final Object fkValue = ((AssociationSimpleDefinition) associationUserGroup).getFKField().getDataAccessor().getValue(userEntity);
        final URI<AccountGroup> groupURI = new URI(userGroupDtDefinition, fkValue);
        return Collections.singleton(groupURI);
    }
    // case N group per user
    // other case checked in postStart by assertions
    Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
    final DtListURI groupDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, accountURI, associationGroupRoleName);
    // -----
    final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(groupDtListURI);
    return result.stream().map(groupEntity -> groupToAccount(groupEntity).getURI()).collect(Collectors.toSet());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) Entity(io.vertigo.dynamo.domain.model.Entity) AccountGroup(io.vertigo.account.account.AccountGroup) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 9 with Account

use of io.vertigo.account.account.Account in project vertigo by KleeGroup.

the class StoreAccountStorePlugin method getAccountURIs.

/**
 * {@inheritDoc}
 */
@Override
public Set<URI<Account>> getAccountURIs(final URI<AccountGroup> groupURI) {
    final DtListURI userDtListURI;
    if (associationUserGroup instanceof AssociationSimpleDefinition) {
        userDtListURI = new DtListURIForSimpleAssociation((AssociationSimpleDefinition) associationUserGroup, groupURI, associationUserRoleName);
    } else {
        // autres cas éliminés par assertion dans le postStart
        Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
        userDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, groupURI, associationUserRoleName);
    }
    // -----
    final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(userDtListURI);
    return result.stream().map(userEntity -> userToAccount(userEntity).getURI()).collect(Collectors.toSet());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 10 with Account

use of io.vertigo.account.account.Account 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;
}
Also used : Account(io.vertigo.account.account.Account) UsernamePasswordAuthenticationToken(io.vertigo.account.impl.authentication.UsernamePasswordAuthenticationToken) AuthenticationToken(io.vertigo.account.authentication.AuthenticationToken) UserSession(io.vertigo.persona.security.UserSession) UsernamePasswordAuthenticationToken(io.vertigo.account.impl.authentication.UsernamePasswordAuthenticationToken)

Aggregations

Account (io.vertigo.account.account.Account)10 URI (io.vertigo.dynamo.domain.model.URI)5 AccountGroup (io.vertigo.account.account.AccountGroup)4 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 AccountStorePlugin (io.vertigo.account.impl.account.AccountStorePlugin)3 VFile (io.vertigo.dynamo.file.model.VFile)3 Assertion (io.vertigo.lang.Assertion)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 Named (javax.inject.Named)3 AuthenticationToken (io.vertigo.account.authentication.AuthenticationToken)2 AccountMapperHelper (io.vertigo.account.impl.account.AccountMapperHelper)2 UsernamePasswordAuthenticationToken (io.vertigo.account.impl.authentication.UsernamePasswordAuthenticationToken)2 AbstractAccountStorePlugin (io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin)2 Home (io.vertigo.app.Home)2 Criteria (io.vertigo.dynamo.criteria.Criteria)2 Criterions (io.vertigo.dynamo.criteria.Criterions)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2