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));
}
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);
}
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);
}
}
}
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());
}
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);
}
}
Aggregations