Search in sources :

Example 1 with UserGroup

use of com.thinkbiganalytics.security.rest.model.UserGroup in project kylo by Teradata.

the class KyloGroupsLoginModule 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);
    final String username;
    final char[] password;
    if (loginUser == null) {
        // Use groups's own username and password to access the REST API if a loginUser was not provided.
        handle(nameCallback, passwordCallback);
        username = nameCallback.getName();
        password = passwordCallback.getPassword();
    } else {
        // Using the loginUser to access API so only need the authenticating groups's name.
        handle(nameCallback);
        username = loginUser;
        password = loginPassword;
    }
    final LoginJerseyClientConfig userConfig = new LoginJerseyClientConfig(config);
    userConfig.setUsername(username);
    userConfig.setPassword(password);
    final List<UserGroup> groups;
    try {
        groups = retrieveGroups(userConfig);
    } catch (Exception e) {
        log.error("An error occurred while getting Kylo Groups username: {}", username, e);
        throw new RuntimeException("An error occurred while getting Kylo Groups", e);
    }
    // Parse response
    if (groups == null) {
        log.debug("Received null response from Groups API for username: {}", username);
        throw new RuntimeException("Received null response from Groups API for username: {} " + username);
    }
    groups.forEach(group -> addNewGroupPrincipal(group.getSystemName()));
    return true;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UserGroup(com.thinkbiganalytics.security.rest.model.UserGroup)

Example 2 with UserGroup

use of com.thinkbiganalytics.security.rest.model.UserGroup in project kylo by Teradata.

the class EntityLevelAccessIT method grantCategoryEntityPermissionToAnalysts.

private void grantCategoryEntityPermissionToAnalysts(String roleName) {
    LOG.debug("EntityLevelAccessIT.grantCategoryEntityPermissionToAnalysts " + roleName);
    runAs(ADMIN);
    RoleMembership roleMembership = category.getRoleMemberships().stream().filter(r -> r.getRole().getSystemName().equalsIgnoreCase(roleName)).findFirst().orElse(null);
    if (roleMembership == null) {
        roleMembership = new RoleMembership(roleName, roleName, roleName);
        category.getRoleMemberships().add(roleMembership);
    }
    roleMembership.addGroup(new UserGroup(GROUP_ANALYSTS));
    Response response = given(FeedCategoryRestController.BASE).body(category).when().post();
    response.then().statusCode(HTTP_OK);
}
Also used : Response(com.jayway.restassured.response.Response) RoleMembership(com.thinkbiganalytics.security.rest.model.RoleMembership) UserGroup(com.thinkbiganalytics.security.rest.model.UserGroup)

Aggregations

UserGroup (com.thinkbiganalytics.security.rest.model.UserGroup)2 Response (com.jayway.restassured.response.Response)1 RoleMembership (com.thinkbiganalytics.security.rest.model.RoleMembership)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1