Skip to content

Commit

Permalink
Merge pull request #1734 from SnehaSuresh-aot/bpm_bug_fix
Browse files Browse the repository at this point in the history
updated admin REST API Implementation
  • Loading branch information
auslin-aot authored Nov 17, 2023
2 parents d5db07b + 7d97d5c commit 24def75
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package org.camunda.bpm.extension.hooks.rest;

import org.camunda.bpm.extension.hooks.controllers.data.AuthorizationInfo;
import org.camunda.bpm.extension.hooks.controllers.data.TenantAuthorizationDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.ServletException;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import reactor.core.publisher.Mono;
import org.camunda.bpm.extension.hooks.controllers.data.AuthorizationInfo;
import org.camunda.bpm.extension.hooks.controllers.data.TenantAuthorizationDto;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Produces({MediaType.APPLICATION_JSON})
public interface AdminRestResource extends RestResource {
Expand All @@ -21,7 +18,7 @@ public interface AdminRestResource extends RestResource {
@GET
@Path("/form/authorization")
@Produces({MediaType.APPLICATION_JSON})
Mono<ResponseEntity<AuthorizationInfo>> getFormAuthorization() throws ServletException;
AuthorizationInfo getFormAuthorization() throws ServletException;

@POST
@Path("/tenant/authorization")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import org.camunda.bpm.extension.hooks.controllers.data.TenantAuthorizationDto;
import org.camunda.bpm.extension.hooks.rest.AdminRestResource;
import org.camunda.bpm.extension.hooks.rest.service.AdminRestService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Mono;

@Component
public class AdminRestResourceImpl implements AdminRestResource {
Expand All @@ -21,7 +19,7 @@ public AdminRestResourceImpl(AdminRestService adminRestService) {
}

@Override
public Mono<ResponseEntity<AuthorizationInfo>> getFormAuthorization() throws ServletException {
public AuthorizationInfo getFormAuthorization() throws ServletException {
return restService.getFormAuthorization();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface AdminRestService {

Mono<ResponseEntity<AuthorizationInfo>> getFormAuthorization() throws ServletException;
AuthorizationInfo getFormAuthorization() throws ServletException;

void createTenant(TenantAuthorizationDto dto) throws ServletException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.camunda.bpm.extension.hooks.rest.service.impl;

import net.minidev.json.JSONArray;
import jakarta.servlet.ServletException;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.AuthorizationService;
import org.camunda.bpm.engine.ProcessEngines;
Expand All @@ -25,9 +25,7 @@
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Mono;

import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.*;

Expand All @@ -54,7 +52,7 @@ public AdminRestServiceImpl(
}

@Override
public Mono<ResponseEntity<AuthorizationInfo>> getFormAuthorization() throws ServletException {
public AuthorizationInfo getFormAuthorization() throws ServletException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
LOGGER.debug("authentication" + authentication);
List<String> groups = getGroups(authentication);
Expand All @@ -67,7 +65,7 @@ public Mono<ResponseEntity<AuthorizationInfo>> getFormAuthorization() throws Ser
} else {
authorizationInfo = fetchAuthorizationInfo(false, groups);
}
return Mono.just(ResponseEntity.ok(authorizationInfo));
return ResponseEntity.ok(authorizationInfo).getBody();
}

private AuthorizationInfo fetchAuthorizationInfo(boolean adminGroupEnabled, List<String> groups){
Expand Down Expand Up @@ -173,8 +171,7 @@ private List<String> getGroups(Authentication authentication) throws ServletExce

private List<String> getKeyValues(Map<String, Object> claims, String claimName, String tenantKey) {
List<String> groupIds = new ArrayList<String>();
JSONArray groups = (JSONArray) claims.get(claimName);
for (Object group1 : groups) {
for (Object group1 : (List<String>) claims.get(claimName)){
String groupName = group1.toString();
if (StringUtils.startsWith(groupName, "/")) {
groupIds.add(StringUtils.substring(groupName, 1));
Expand Down

0 comments on commit 24def75

Please sign in to comment.