use of com.redhat.cloud.notifications.models.InternalRoleAccess in project notifications-backend by RedHatInsights.
the class InternalPermissionResource method getPermissions.
@GET
@Path("/me")
@Produces(MediaType.APPLICATION_JSON)
// Overrides admin permission
@RolesAllowed(ConsoleIdentityProvider.RBAC_INTERNAL_USER)
public InternalUserPermissions getPermissions() {
InternalUserPermissions permissions = new InternalUserPermissions();
if (securityIdentity.hasRole(ConsoleIdentityProvider.RBAC_INTERNAL_ADMIN)) {
permissions.setAdmin(true);
return permissions;
}
String privateRolePrefix = InternalRoleAccess.INTERNAL_ROLE_PREFIX;
Set<String> roles = securityIdentity.getRoles().stream().filter(s -> s.startsWith(privateRolePrefix)).map(s -> s.substring(privateRolePrefix.length())).collect(Collectors.toSet());
permissions.getRoles().addAll(roles);
List<InternalRoleAccess> accessList = internalRoleAccessRepository.getByRoles(roles);
for (InternalRoleAccess access : accessList) {
permissions.addApplication(access.getApplicationId(), access.getApplication().getDisplayName());
}
return permissions;
}
use of com.redhat.cloud.notifications.models.InternalRoleAccess in project notifications-backend by RedHatInsights.
the class InternalResource method createApplication.
@POST
@Path("/applications")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Transactional
@RolesAllowed(ConsoleIdentityProvider.RBAC_INTERNAL_USER)
public Application createApplication(@Context SecurityContext sec, @NotNull @Valid AddApplicationRequest request) {
securityContextUtil.hasPermissionForRole(sec, request.ownerRole);
Application app = new Application();
app.setBundleId(request.bundleId);
app.setDisplayName(request.displayName);
app.setName(request.name);
app = applicationRepository.createApp(app);
if (request.ownerRole != null) {
InternalRoleAccess access = new InternalRoleAccess();
access.setRole(request.ownerRole);
access.setApplicationId(app.getId());
access.setApplication(app);
internalRoleAccessRepository.addAccess(access);
}
return app;
}
use of com.redhat.cloud.notifications.models.InternalRoleAccess in project notifications-backend by RedHatInsights.
the class InternalPermissionResource method addAccess.
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public InternalRoleAccess addAccess(@Valid AddAccessRequest addAccessRequest) {
InternalRoleAccess access = new InternalRoleAccess();
Application application = applicationRepository.getApplication(addAccessRequest.applicationId);
access.setApplicationId(addAccessRequest.applicationId);
access.setRole(addAccessRequest.role);
access.setApplication(application);
return internalRoleAccessRepository.addAccess(access);
}
Aggregations