use of com.objectcomputing.checkins.services.permissions.Permission in project check-ins by objectcomputing.
the class CurrentUserController method currentUser.
/**
* Get user details from Google authentication
*
* @param authentication {@link Authentication} or null
* @return {@link HttpResponse<CurrentUserDTO>}
*/
@Get
public HttpResponse<CurrentUserDTO> currentUser(@Nullable Authentication authentication) {
if (authentication == null) {
return HttpResponse.unauthorized();
}
String workEmail = authentication.getAttributes().get("email").toString();
String imageUrl = authentication.getAttributes().get("picture") != null ? authentication.getAttributes().get("picture").toString() : "";
String name = authentication.getAttributes().get("name").toString().trim();
String firstName = name.substring(0, name.indexOf(' '));
String lastName = name.substring(name.indexOf(' ') + 1).trim();
MemberProfile user = currentUserServices.findOrSaveUser(firstName, lastName, workEmail);
List<Permission> permissions = permissionServices.findUserPermissions(user.getId());
Set<Role> roles = roleServices.findUserRoles(user.getId());
List<String> rolesAsString = roles.stream().map(o -> o.getRole()).collect(Collectors.toList());
return HttpResponse.ok().headers(headers -> headers.location(location(user.getId()))).body(fromEntity(user, imageUrl, permissions, rolesAsString));
}
use of com.objectcomputing.checkins.services.permissions.Permission in project check-ins by objectcomputing.
the class PermissionFixture method setPermissionsForAdmin.
default void setPermissionsForAdmin(UUID roleID) {
List<Permission> permissions = getPermissionRepository().findAll();
for (Permissions adminPermission : adminPermissions) {
Optional<Permission> permission = permissions.stream().filter(s -> s.getPermission().equals(adminPermission.name())).findFirst();
permission.ifPresent(value -> setRolePermission(roleID, value.getId()));
}
}
use of com.objectcomputing.checkins.services.permissions.Permission in project check-ins by objectcomputing.
the class PermissionFixture method setPermissionsForMember.
default void setPermissionsForMember(UUID roleID) {
List<Permission> permissions = getPermissionRepository().findAll();
for (Permissions memberPermission : memberPermissions) {
Optional<Permission> permission = permissions.stream().filter(s -> s.getPermission().equals(memberPermission.name())).findFirst();
permission.ifPresent(value -> setRolePermission(roleID, value.getId()));
}
}
use of com.objectcomputing.checkins.services.permissions.Permission in project check-ins by objectcomputing.
the class RolePermissionServicesImpl method findAll.
public List<RolePermissionResponseDTO> findAll() {
List<RolePermissionResponseDTO> roleInfo = new ArrayList<>();
List<RolePermission> records = rolePermissionRepository.findAll();
List<Role> roles = roleServices.findAllRoles();
List<Permission> permissions = permissionServices.findAll();
for (Role role : roles) {
List<Permission> permissionsAssociatedWithRole = new ArrayList<>();
for (RolePermission rolePermission : records) {
if (role.getId().equals(rolePermission.getRoleId())) {
Optional<Permission> permission = permissions.stream().filter(s -> s.getId().equals(rolePermission.getPermissionId())).findFirst();
permission.ifPresent(permissionsAssociatedWithRole::add);
}
}
RolePermissionResponseDTO rolePermissionResponseDTO = new RolePermissionResponseDTO();
rolePermissionResponseDTO.setRoleId(role.getId());
rolePermissionResponseDTO.setRole(role.getRole());
rolePermissionResponseDTO.setDescription(role.getDescription());
rolePermissionResponseDTO.setPermissions(permissionsAssociatedWithRole);
roleInfo.add(rolePermissionResponseDTO);
}
return roleInfo;
}
use of com.objectcomputing.checkins.services.permissions.Permission in project check-ins by objectcomputing.
the class LocalUserPasswordAuthProvider method authenticate.
@Override
public Publisher<AuthenticationResponse> authenticate(@Nullable HttpRequest<?> httpRequest, AuthenticationRequest<?, ?> authReq) {
String email = authReq.getIdentity().toString();
MemberProfile memberProfile = currentUserServices.findOrSaveUser(email, email, email);
String role;
// if empty get default roles, otherwise create role on the fly
if (StringUtils.isNotEmpty(role = authReq.getSecret().toString())) {
List<String> roles = usersStore.getUserRole(role);
if (roles == null) {
return Flowable.just(new AuthenticationFailed(String.format("Invalid role selected %s", role)));
}
// remove a user from the roles they currently have (as assigned in test data)
memberRoleServices.removeMemberFromRoles(memberProfile.getId());
// add the roles based on role override / configuration properties
for (String curRole : roles) {
// if no role is found then create and save it
Role currentRole = roleServices.findByRole(curRole).orElse(null);
if (currentRole == null) {
currentRole = roleServices.save(new Role(null, curRole, "description"));
}
memberRoleServices.saveByIds(memberProfile.getId(), currentRole.getId());
}
}
List<Permission> permissions = permissionServices.findUserPermissions(memberProfile.getId());
List<String> permissionsAsString = permissions.stream().map(o -> o.getPermission()).collect(Collectors.toList());
Set<Role> userRoles = roleServices.findUserRoles(memberProfile.getId());
List<String> rolesAsString = userRoles.stream().map(o -> o.getRole()).collect(Collectors.toList());
Map<String, Object> attributes = new HashMap<>();
attributes.put("permissions", permissionsAsString);
attributes.put("email", memberProfile.getWorkEmail());
return Flowable.just(new ExtendedUserDetails(email, rolesAsString, attributes));
}
Aggregations