Search in sources :

Example 1 with RoleMembership

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

the class SecurityModelTransform method applyAccessControl.

public void applyAccessControl(AccessControlled domain, EntityAccessControl restModel) {
    if (domain.getAllowedActions() != null && domain.getAllowedActions().getAvailableActions() != null) {
        ActionGroup allowed = toActionGroup(null).apply(domain.getAllowedActions());
        restModel.setAllowedActions(allowed);
    }
    if (domain.getRoleMemberships() != null) {
        Map<String, RoleMembership> roleAssignmentMap = new HashMap<>();
        domain.getRoleMemberships().stream().forEach(membership -> {
            String systemRoleName = membership.getRole().getSystemName();
            String name = membership.getRole().getTitle();
            String desc = membership.getRole().getDescription();
            membership.getMembers().stream().forEach(member -> {
                roleAssignmentMap.putIfAbsent(systemRoleName, new RoleMembership(systemRoleName, name, desc));
                RoleMembership accessRoleAssignment = roleAssignmentMap.get(systemRoleName);
                if (member instanceof UsernamePrincipal) {
                    accessRoleAssignment.addUser(member.getName());
                } else {
                    accessRoleAssignment.addGroup(member.getName());
                }
            });
        });
        restModel.setRoleMemberships(Lists.newArrayList(roleAssignmentMap.values()));
    }
    Principal owner = domain.getOwner();
    Optional<User> userPrincipal = userService.getUser(owner.getName());
    if (userPrincipal.isPresent()) {
        restModel.setOwner(userPrincipal.get());
    }
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) User(com.thinkbiganalytics.security.rest.model.User) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) HashMap(java.util.HashMap) RoleMembership(com.thinkbiganalytics.security.rest.model.RoleMembership) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Principal(java.security.Principal)

Example 2 with RoleMembership

use of com.thinkbiganalytics.security.rest.model.RoleMembership 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

RoleMembership (com.thinkbiganalytics.security.rest.model.RoleMembership)2 Response (com.jayway.restassured.response.Response)1 GroupPrincipal (com.thinkbiganalytics.security.GroupPrincipal)1 UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)1 ActionGroup (com.thinkbiganalytics.security.rest.model.ActionGroup)1 User (com.thinkbiganalytics.security.rest.model.User)1 UserGroup (com.thinkbiganalytics.security.rest.model.UserGroup)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1