From b4e4dfc49b52fe0fbc5884ca4e04bcedc35361f4 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 31 Oct 2023 12:37:53 +0000 Subject: [PATCH] admin role fixes --- .../services/impl/SecurityTokenServiceImpl.java | 9 ++++----- .../src/main/resources/openapi.yml | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java index 726996ef..3103c41b 100644 --- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java +++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/SecurityTokenServiceImpl.java @@ -25,6 +25,7 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; +import com.fasterxml.uuid.Logger; import eclipse.tractusx.demand_capacity_mgmt_specification.model.IntrospectTokenResponse; import eclipse.tractusx.demand_capacity_mgmt_specification.model.Role; import eclipse.tractusx.demand_capacity_mgmt_specification.model.TokenResponse; @@ -230,11 +231,9 @@ private UserEntity generateUser(String userID, DecodedJWT decodedJWT) { Object rolesObject = realmAccessMap.get("roles"); - if (rolesObject instanceof List) { - List list = (List) rolesObject; + if (rolesObject instanceof List list) { for (Object roleObj : list) { - if (roleObj instanceof String) { - String roleStr = (String) roleObj; + if (roleObj instanceof String roleStr) { try { org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role role = org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.entities.enums.Role.valueOf( roleStr @@ -242,7 +241,7 @@ private UserEntity generateUser(String userID, DecodedJWT decodedJWT) { newUserEntity.setRole(role); break; } catch (IllegalArgumentException e) { - throw new RuntimeException("Illegal Role detected! User must have one of the role types"); + Logger.logError("Incompatible role! User must have one of the 3 role types 'ADMIN','CUSTOMER','SUPPLIER'"); } } } diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml index ef289844..c34f15bb 100644 --- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml +++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml @@ -918,6 +918,7 @@ components: enum: - CUSTOMER - SUPPLIER + - ADMIN TokenResponse: type: object properties: