use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentRepositoryTest method testFindById.
@Test
public void testFindById() {
Environment environment = buildEnv();
// TODO: find another way to inject data in DB. Avoid to rely on class under test for that.
Environment envCreated = environmentRepository.create(environment).blockingGet();
TestObserver<Environment> obs = environmentRepository.findById(envCreated.getId()).test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertNoErrors();
obs.assertValue(e -> e.getId().equals(envCreated.getId()));
obs.assertValue(e -> e.getName().equals(environment.getName()));
obs.assertValue(e -> e.getDescription().equals(environment.getDescription()));
obs.assertValue(e -> e.getOrganizationId().equals(environment.getOrganizationId()));
obs.assertValue(e -> e.getDomainRestrictions().containsAll(environment.getDomainRestrictions()));
obs.assertValue(e -> e.getHrids().containsAll(environment.getHrids()));
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentRepositoryTest method buildEnv.
private Environment buildEnv() {
Environment env = new Environment();
env.setName("testName");
env.setDescription("testDescription");
env.setCreatedAt(new Date());
env.setUpdatedAt(env.getUpdatedAt());
env.setOrganizationId(UUID.randomUUID().toString());
env.setDomainRestrictions(Arrays.asList("ValueDom1", "ValueDom2"));
env.setHrids(Arrays.asList("Hrid1", "Hrid2"));
return env;
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class CockpitAuthenticationFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (enabled && httpRequest.getPathInfo().equals("/cockpit")) {
String token = request.getParameter("token");
if (StringUtils.isEmpty(token)) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
} else {
try {
JWT jwt = jwtParser.parse(token);
UsernamePasswordAuthenticationToken authentication = convertToAuthentication(jwt);
User principal = authenticationService.onAuthenticationSuccess(authentication);
final Environment environment = environmentService.findById((String) jwt.get(Claims.environment), (String) jwt.get(Claims.organization)).blockingGet();
String redirectPath = "";
if (environment != null) {
redirectPath = "/environments/" + environment.getHrids().get(0);
}
Cookie jwtAuthenticationCookie = jwtGenerator.generateCookie(principal);
httpResponse.addCookie(jwtAuthenticationCookie);
httpResponse.sendRedirect((String) jwt.get("redirect_uri") + redirectPath);
} catch (Exception e) {
LOGGER.error("Error occurred when trying to login using cockpit.", e);
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
}
}
} else {
chain.doFilter(request, response);
}
}
use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.
the class EnvironmentCommandHandlerTest method handle.
@Test
public void handle() {
EnvironmentPayload environmentPayload = new EnvironmentPayload();
EnvironmentCommand command = new EnvironmentCommand(environmentPayload);
environmentPayload.setId("env#1");
environmentPayload.setHrids(Collections.singletonList("env-1"));
environmentPayload.setOrganizationId("orga#1");
environmentPayload.setDescription("Environment description");
environmentPayload.setName("Environment name");
environmentPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(environmentService.createOrUpdate(eq("orga#1"), eq("env#1"), argThat(newEnvironment -> newEnvironment.getHrids().equals(environmentPayload.getHrids()) && newEnvironment.getDescription().equals(environmentPayload.getDescription()) && newEnvironment.getName().equals(environmentPayload.getName()) && newEnvironment.getDomainRestrictions().equals(environmentPayload.getDomainRestrictions())), isNull())).thenReturn(Single.just(new Environment()));
TestObserver<EnvironmentReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
Aggregations