public TenantModelDao(final Tenant tenant) { this(tenant.getId(), tenant.getCreatedDate(), tenant.getUpdatedDate(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret(), null); }
public CallContext createCallContextWithAccountId(final UUID accountId, final String createdBy, final String reason, final String comment, final ServletRequest request) throws IllegalArgumentException { try { Preconditions.checkNotNull(createdBy, String.format("Header %s needs to be set", JaxrsResource.HDR_CREATED_BY)); final Tenant tenant = getTenantFromRequest(request); final UUID tenantId = tenant == null ? null : tenant.getId(); final CallContext callContext = contextFactory.createCallContext(accountId, tenantId, createdBy, origin, userType, reason, comment, getOrCreateUserToken()); populateMDCContext(callContext); return callContext; } catch (final NullPointerException e) { throw new IllegalArgumentException(e.getMessage()); } }
@TimedResource @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Create a tenant", response = TenantJson.class) @ApiResponses(value = {@ApiResponse(code = 201, message = "Tenant created successfully"), @ApiResponse(code = 409, message = "Tenant already exists")}) public Response createTenant(final TenantJson json, @QueryParam(QUERY_TENANT_USE_GLOBAL_DEFAULT) @DefaultValue("false") final Boolean useGlobalDefault, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException, CatalogApiException { verifyNonNullOrEmpty(json, "TenantJson body should be specified"); verifyNonNullOrEmpty(json.getApiKey(), "TenantJson apiKey needs to be set", json.getApiSecret(), "TenantJson apiSecret needs to be set"); final TenantData data = json.toTenantData(); final Tenant tenant = tenantApi.createTenant(data, context.createCallContextNoAccountId(createdBy, reason, comment, request)); if (!useGlobalDefault) { final CallContext callContext = new DefaultCallContext(null, tenant.getId(), createdBy, CallOrigin.EXTERNAL, UserType.CUSTOMER, Context.getOrCreateUserToken(), clock); catalogUserApi.createDefaultEmptyCatalog(null, callContext); } return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId(), request); }
public TenantJson(final Tenant tenant) { this(tenant.getId(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret()); }
public TenantContext createTenantContextWithAccountId(final UUID accountId, final ServletRequest request) { final TenantContext tenantContext; final Tenant tenant = getTenantFromRequest(request); if (tenant == null) { // Multi-tenancy may not have been configured - default to "default" tenant (see InternalCallContextFactory) tenantContext = contextFactory.createTenantContext(accountId, null); } else { tenantContext = contextFactory.createTenantContext(accountId, tenant.getId()); } populateMDCContext(tenantContext); return tenantContext; }
public TenantModelDao(final Tenant tenant) { this(tenant.getId(), tenant.getCreatedDate(), tenant.getUpdatedDate(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret(), null); }
private void setupTenant() throws TenantApiException { final UUID uuid = UUID.randomUUID(); final String externalKey = uuid.toString(); final String apiKey = externalKey + "-Key"; final String apiSecret = externalKey + "-$3cr3t"; // Only place where we use callContext tenant = tenantUserApi.createTenant(new DefaultTenant(uuid, init, init, externalKey, apiKey, apiSecret), callContext); testCallContext = new DefaultCallContext(null, tenant.getId(), "tester", CallOrigin.EXTERNAL, UserType.TEST, "good reason", "trust me", uuid, clock); }
tenantRecordIdCacheController.remove(currentTenant.getId().toString());
@Test(groups = "slow") public void testTenantKVChange() throws Exception { final TenantData tenantData = new DefaultTenant(null, clock.getUTCNow(), clock.getUTCNow(), "MY_TENANT", "key", "s3Cr3T"); final CallContext contextWithNoTenant = new DefaultCallContext(null, null, "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock); final Tenant tenant = tenantUserApi.createTenant(tenantData, contextWithNoTenant); final CallContext contextWithTenant = new DefaultCallContext(null, tenant.getId(), "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock); final String tenantKey = TenantKey.PLUGIN_CONFIG_ + "FOO"; tenantUserApi.addTenantKeyValue(tenantKey, "FOO", contextWithTenant); await().atMost(10, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { // expecting TENANT_CONFIG_CHANGE return externalBusCount.get() == 1; } }); }