mirror of
https://github.com/valitydev/org-manager.git
synced 2024-11-06 00:15:23 +00:00
commit
8e87c2ba8a
11
pom.xml
11
pom.xml
@ -85,6 +85,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -186,6 +192,11 @@
|
||||
<artifactId>jackson-databind-nullable</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>9.0.45</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--test-->
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.rbkmoney.orgmanager.exception;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
@ -24,4 +26,12 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
.build();
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = {BouncerException.class})
|
||||
protected ResponseEntity<Object> handleBouncerException(BouncerException ex, WebRequest request) {
|
||||
log.error(ex.getMessage(), ex.getCause());
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.FAILED_DEPENDENCY)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,6 @@
|
||||
package com.rbkmoney.orgmanager.service;
|
||||
|
||||
import com.rbkmoney.bouncer.context.v1.Auth;
|
||||
import com.rbkmoney.bouncer.context.v1.ContextFragment;
|
||||
import com.rbkmoney.bouncer.context.v1.ContextOrgManagement;
|
||||
import com.rbkmoney.bouncer.context.v1.Deployment;
|
||||
import com.rbkmoney.bouncer.context.v1.Entity;
|
||||
import com.rbkmoney.bouncer.context.v1.Environment;
|
||||
import com.rbkmoney.bouncer.context.v1.Invitee;
|
||||
import com.rbkmoney.bouncer.context.v1.OrgManagementInvitation;
|
||||
import com.rbkmoney.bouncer.context.v1.OrgManagementOperation;
|
||||
import com.rbkmoney.bouncer.context.v1.OrgRole;
|
||||
import com.rbkmoney.bouncer.context.v1.OrgRoleScope;
|
||||
import com.rbkmoney.bouncer.context.v1.Token;
|
||||
import com.rbkmoney.bouncer.context.v1.User;
|
||||
import com.rbkmoney.bouncer.context.v1.*;
|
||||
import com.rbkmoney.bouncer.ctx.ContextFragmentType;
|
||||
import com.rbkmoney.bouncer.decisions.Context;
|
||||
import com.rbkmoney.orgmanagement.UserNotFound;
|
||||
@ -20,6 +8,7 @@ import com.rbkmoney.orgmanager.config.properties.BouncerProperties;
|
||||
import com.rbkmoney.orgmanager.service.dto.BouncerContextDto;
|
||||
import com.rbkmoney.orgmanager.service.dto.InvitationDto;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
@ -28,6 +17,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BouncerContextFactory {
|
||||
@ -59,11 +49,13 @@ public class BouncerContextFactory {
|
||||
.setExpiration(expiration);
|
||||
// TODO надо ли доставать requester?
|
||||
ContextOrgManagement contextOrgManagement = buildOrgManagementContext(bouncerContext);
|
||||
return new ContextFragment()
|
||||
ContextFragment contextFragment = new ContextFragment()
|
||||
.setAuth(auth)
|
||||
.setUser(user)
|
||||
.setEnv(env)
|
||||
.setOrgmgmt(contextOrgManagement);
|
||||
log.debug("Context fragment to bouncer {}", contextFragment);
|
||||
return contextFragment;
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.rbkmoney.orgmanager.entity.MemberEntity;
|
||||
import com.rbkmoney.orgmanager.entity.MemberRoleEntity;
|
||||
import com.rbkmoney.orgmanager.entity.OrganizationEntity;
|
||||
import com.rbkmoney.orgmanager.exception.AccessDeniedException;
|
||||
import com.rbkmoney.orgmanager.exception.BouncerException;
|
||||
import com.rbkmoney.orgmanager.util.TestData;
|
||||
import com.rbkmoney.swag.organizations.model.InvitationRequest;
|
||||
import com.rbkmoney.swag.organizations.model.MemberRole;
|
||||
@ -31,6 +32,18 @@ public class OrgsControllerTest extends AbstractControllerTest {
|
||||
|
||||
public static final String MEMBER_ID = "L6Mc2la1D9Rg";
|
||||
|
||||
@Test
|
||||
void expelOrgMemberWithErrorCallBouncer() throws Exception {
|
||||
doThrow(new BouncerException("Error bouncer", new RuntimeException())).when(resourceAccessService)
|
||||
.checkMemberRights(ORGANIZATION_ID, MEMBER_ID);
|
||||
|
||||
mockMvc.perform(delete(String.format("/orgs/%s/members/%s", ORGANIZATION_ID, MEMBER_ID))
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "Bearer " + generateRBKadminJwt())
|
||||
.header("X-Request-ID", "testRequestId"))
|
||||
.andExpect(status().isFailedDependency());
|
||||
}
|
||||
|
||||
@Test
|
||||
void expelOrgMemberWithoutAccess() throws Exception {
|
||||
doThrow(new AccessDeniedException("Access denied")).when(resourceAccessService)
|
||||
|
@ -1,12 +1,6 @@
|
||||
package com.rbkmoney.orgmanager.service;
|
||||
|
||||
import com.rbkmoney.bouncer.decisions.ArbiterSrv;
|
||||
import com.rbkmoney.bouncer.decisions.Context;
|
||||
import com.rbkmoney.bouncer.decisions.Judgement;
|
||||
import com.rbkmoney.bouncer.decisions.Resolution;
|
||||
import com.rbkmoney.bouncer.decisions.ResolutionAllowed;
|
||||
import com.rbkmoney.bouncer.decisions.ResolutionRestricted;
|
||||
import com.rbkmoney.bouncer.decisions.RulesetNotFound;
|
||||
import com.rbkmoney.bouncer.decisions.*;
|
||||
import com.rbkmoney.orgmanagement.UserNotFound;
|
||||
import com.rbkmoney.orgmanager.TestObjectFactory;
|
||||
import com.rbkmoney.orgmanager.config.properties.BouncerProperties;
|
||||
@ -21,9 +15,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
Loading…
Reference in New Issue
Block a user