Search in sources :

Example 1 with Account

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

the class TextAccountStorePlugin method parseAccounts.

private void parseAccounts(final String line) {
    final Matcher matcher = accountFilePattern.matcher(line);
    final boolean matches = matcher.matches();
    Assertion.checkState(matches, "AccountFile ({2}) can't be parse by this regexp :\nline:{0}\nregexp:{1}", line, matches, accountFilePath);
    final String id = matcher.group(AccountProperty.id.name());
    final String displayName = matcher.group(AccountProperty.displayName.name());
    final String email = matcher.group(AccountProperty.email.name());
    final String authToken = matcher.group(AccountProperty.authToken.name());
    final String photoUrl = matcher.group(AccountProperty.photoUrl.name());
    final Account account = Account.builder(id).withDisplayName(displayName).withEmail(email).withAuthToken(authToken).build();
    accounts.put(id, new AccountInfo(account, photoUrl));
}
Also used : Account(io.vertigo.account.account.Account) Matcher(java.util.regex.Matcher)

Example 2 with Account

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

the class TextAccountStorePlugin method parseGroups.

private void parseGroups(final String line) {
    final Matcher matcher = groupFilePattern.matcher(line);
    final boolean matches = matcher.matches();
    Assertion.checkState(matches, "GroupFile ({2}) can't be parse by this regexp :\nline:{0}\nregexp:{1}", line, matches, groupFilePath);
    final String groupId = matcher.group(GroupProperty.id.name());
    final String displayName = matcher.group(GroupProperty.displayName.name());
    final String accountIds = matcher.group(GroupProperty.accountIds.name());
    final AccountGroup accountGroup = new AccountGroup(groupId, displayName);
    groups.put(groupId, accountGroup);
    final List<Account> groupAccounts = new ArrayList<>();
    for (final String accountId : accountIds.split(";")) {
        groupsPerAccount.computeIfAbsent(accountId, k -> new ArrayList<>()).add(accountGroup);
        final Account account = accounts.get(accountId).getAccount();
        Assertion.checkNotNull(account, "Group {0} reference an undeclared account {1}", groupId, accountId);
        groupAccounts.add(account);
    }
    accountsPerGroup.put(groupId, groupAccounts);
}
Also used : URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) URISyntaxException(java.net.URISyntaxException) Scanner(java.util.Scanner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Matcher(java.util.regex.Matcher) WrappedException(io.vertigo.lang.WrappedException) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Named(javax.inject.Named) AccountGroup(io.vertigo.account.account.AccountGroup) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Consumer(java.util.function.Consumer) List(java.util.List) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) FSFile(io.vertigo.dynamo.impl.file.model.FSFile) Activeable(io.vertigo.core.component.Activeable) Account(io.vertigo.account.account.Account) Optional(java.util.Optional) ResourceManager(io.vertigo.core.resource.ResourceManager) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) Account(io.vertigo.account.account.Account) AccountGroup(io.vertigo.account.account.AccountGroup) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 3 with Account

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

the class RedisAccountCachePlugin method attach.

/*
	@Override
	public Collection<AccountGroup> getAllGroups() {
		final List<Response<Map<String, String>>> responses = new ArrayList<>();
		try (final Jedis jedis = redisConnector.getResource()) {
			final Set<String> ids = jedis.smembers(SACCOUNTS_KEY);
			try (final Transaction tx = jedis.multi()) {
				for (final String id : ids) {
					responses.add(tx.hgetAll(HACCOUNT_START_KEY + id));
				}
				tx.exec();
			} catch (final IOException ex) {
				throw WrappedException.wrap(ex);
			}
	
		}
		//----- we are using tx to avoid roundtrips
		final List<AccountGroup> groups = new ArrayList<>();
		for (final Response<Map<String, String>> response : responses) {
			final Map<String, String> data = response.get();
			if (!data.isEmpty()) {
				groups.add(map2Group(data));
			}
		}
		return groups;
	}*/
/**
 * {@inheritDoc}
 */
@Override
public void attach(final Set<URI<Account>> accountsURI, final URI<AccountGroup> groupURI) {
    Assertion.checkNotNull(accountsURI);
    Assertion.checkNotNull(groupURI);
    // -----
    try (final Jedis jedis = redisConnector.getResource()) {
        try (final Transaction tx = jedis.multi()) {
            for (final URI<Account> accountURI : accountsURI) {
                tx.sadd(SACCOUNTS_BY_GROUP_START_KEY + groupURI.getId(), accountURI.getId().toString());
                tx.sadd(SGROUPS_BY_ACCOUNT_START_KEY + accountURI.getId(), groupURI.getId().toString());
            }
            tx.exec();
        } catch (final IOException ex) {
            throw WrappedException.wrap(ex);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Account(io.vertigo.account.account.Account) Transaction(redis.clients.jedis.Transaction) IOException(java.io.IOException)

Example 4 with Account

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

the class AuthenticationManagerTest method testLoginFail.

@Test
public void testLoginFail() {
    final AuthenticationToken token = new UsernamePasswordAuthenticationToken("badUserName", "badPassword");
    final Optional<Account> account = authenticationManager.login(token);
    Assert.assertFalse("Shouldn't found any account with a bad login", account.isPresent());
    final Optional<UserSession> userSession = securityManager.getCurrentUserSession();
    Assert.assertTrue("No UserSession", userSession.isPresent());
    Assert.assertFalse("Badly authenticated", userSession.get().isAuthenticated());
}
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) Test(org.junit.Test)

Example 5 with Account

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

the class TestIdentities method initData.

public void initData() {
    final Account testAccount0 = Account.builder("0").withAuthToken("john.doe").withDisplayName("John doe").withEmail("john.doe@yopmail.com").build();
    final Account testAccount1 = Account.builder("1").withAuthToken("palmer.luckey").withDisplayName("Palmer Luckey").withEmail("palmer.luckey@yopmail.com").build();
    final Account testAccount2 = Account.builder("2").withAuthToken("bill.clinton").withDisplayName("Bill Clinton").withEmail("bill.clinton@yopmail.com").build();
    final Account testAccount3 = Account.builder("3").withAuthToken("admin").withDisplayName("Phil Mormon").withEmail("phil.mormon@yopmail.com").build();
    saveAccounts(Arrays.asList(testAccount0, testAccount1, testAccount2, testAccount3));
    final URI<Account> accountURI0 = createAccountURI(testAccount0.getId());
    final URI<Account> accountURI1 = createAccountURI(testAccount1.getId());
    final URI<Account> accountURI2 = createAccountURI(testAccount2.getId());
    final AccountGroup testAccountGroup1 = new AccountGroup("100", "TIME's cover");
    final URI<AccountGroup> group1Uri = DtObjectUtil.createURI(AccountGroup.class, testAccountGroup1.getId());
    saveGroup(testAccountGroup1);
    attach(accountURI1, group1Uri);
    attach(accountURI2, group1Uri);
    final AccountGroup groupAll = new AccountGroup("ALL", "Everyone");
    final URI<AccountGroup> groupAllUri = DtObjectUtil.createURI(AccountGroup.class, groupAll.getId());
    saveGroup(groupAll);
    attach(accountURI0, groupAllUri);
    attach(accountURI1, groupAllUri);
    attach(accountURI2, groupAllUri);
    // ---create 10 noisy data
    final List<Account> accounts = createAccounts();
    saveAccounts(accounts);
    for (final Account account : accounts) {
        final URI<Account> accountUri = createAccountURI(account.getId());
        attach(accountUri, groupAllUri);
    }
}
Also used : Account(io.vertigo.account.account.Account) AccountGroup(io.vertigo.account.account.AccountGroup)

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