use of com.thinkbiganalytics.metadata.api.user.User in project kylo by Teradata.
the class KyloLoginModule method doLogin.
@Override
protected boolean doLogin() throws Exception {
// Get username and password
final NameCallback nameCallback = new NameCallback("Username: ");
final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
if (requirePassword) {
handle(nameCallback, passwordCallback);
} else {
handle(nameCallback);
}
// Authenticate user
metadata.read(() -> {
Optional<User> user = userProvider.findUserBySystemName(nameCallback.getName());
if (user.isPresent()) {
if (!user.get().isEnabled()) {
throw new AccountLockedException("The account \"" + nameCallback.getName() + "\" is currently disabled");
} else if (requirePassword && !passwordEncoder.matches(new String(passwordCallback.getPassword()), user.get().getPassword())) {
throw new CredentialException("The username and/or password combination do not match");
}
addPrincipal(user.get().getPrincipal());
addAllPrincipals(user.get().getAllGroupPrincipals());
} else {
throw new AccountNotFoundException("No account exists with name name \"" + nameCallback.getName() + "\"");
}
}, MetadataAccess.SERVICE);
return true;
}
use of com.thinkbiganalytics.metadata.api.user.User in project kylo by Teradata.
the class JcrUserProviderTest method testUserGetContainingGroups.
@Test(dependsOnMethods = "testAddUsersMembers")
public void testUserGetContainingGroups() {
metadata.read(() -> {
User user1 = this.provider.findUserBySystemName("user1").get();
User user2 = this.provider.findUserBySystemName("user2").get();
User user3 = this.provider.findUserBySystemName("user3").get();
assertThat(user1.getContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupA");
assertThat(user2.getContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupB");
assertThat(user3.getContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupD");
});
}
use of com.thinkbiganalytics.metadata.api.user.User in project kylo by Teradata.
the class JcrUserProviderTest method testUserGetAllContainingGroups.
@Test(dependsOnMethods = "testAddUsersMembers")
public void testUserGetAllContainingGroups() {
metadata.read(() -> {
User user1 = this.provider.findUserBySystemName("user1").get();
User user2 = this.provider.findUserBySystemName("user2").get();
User user3 = this.provider.findUserBySystemName("user3").get();
assertThat(user1.getAllContainingGroups()).hasSize(1).extracting(g -> g.getSystemName()).contains("groupA");
assertThat(user2.getAllContainingGroups()).hasSize(2).extracting(g -> g.getSystemName()).contains("groupB", "groupA");
assertThat(user3.getAllContainingGroups()).hasSize(3).extracting(g -> g.getSystemName()).contains("groupD", "groupC", "groupA");
});
}
use of com.thinkbiganalytics.metadata.api.user.User in project kylo by Teradata.
the class JcrUserProviderTest method testUserGetGroupPrincipals.
@Test(dependsOnMethods = "testAddUsersMembers")
public void testUserGetGroupPrincipals() {
metadata.read(() -> {
User user1 = this.provider.findUserBySystemName("user1").get();
User user2 = this.provider.findUserBySystemName("user2").get();
User user3 = this.provider.findUserBySystemName("user3").get();
assertThat(user1.getAllGroupPrincipals()).hasSize(1).contains(new GroupPrincipal("groupA"));
assertThat(user2.getAllGroupPrincipals()).hasSize(2).contains(new GroupPrincipal("groupA"), new GroupPrincipal("groupB"));
assertThat(user3.getAllGroupPrincipals()).hasSize(3).contains(new GroupPrincipal("groupA"), new GroupPrincipal("groupC"), new GroupPrincipal("groupD"));
});
}
use of com.thinkbiganalytics.metadata.api.user.User in project kylo by Teradata.
the class CreateDefaultUsersGroupsAction method createDefaultUser.
protected User createDefaultUser(String username, String displayName, String password) {
Optional<User> userOption = userProvider.findUserBySystemName(username);
User user = null;
// Create the user if it doesn't exists.
if (userOption.isPresent()) {
user = userOption.get();
} else {
user = userProvider.ensureUser(username);
if (password != null) {
user.setPassword(passwordEncoder.encode(password));
}
user.setDisplayName(displayName);
}
return user;
}
Aggregations