Search in sources :

Example 6 with TenantApiException

use of org.killbill.billing.tenant.api.TenantApiException in project killbill by killbill.

the class DefaultOverdueApi method uploadOverdueConfig.

@Override
public void uploadOverdueConfig(final String overdueXML, final CallContext callContext) throws OverdueApiException {
    try {
        final InternalTenantContext internalTenantContext = createInternalTenantContext(callContext);
        final String tenantKey = TenantKey.OVERDUE_CONFIG.toString();
        if (!tenantApi.getTenantValuesForKey(tenantKey, callContext).isEmpty()) {
            tenantApi.deleteTenantKey(tenantKey, callContext);
        }
        tenantApi.addTenantKeyValue(tenantKey, overdueXML, callContext);
        overdueConfigCache.clearOverdueConfig(internalTenantContext);
    } catch (final TenantApiException e) {
        throw new OverdueApiException(e);
    }
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantApiException(org.killbill.billing.tenant.api.TenantApiException)

Example 7 with TenantApiException

use of org.killbill.billing.tenant.api.TenantApiException in project killbill by killbill.

the class DefaultTenantDao method create.

@Override
public void create(final TenantModelDao entity, final InternalCallContext context) throws TenantApiException {
    // Create the salt and password
    final ByteSource salt = rng.nextBytes();
    // Hash the plain-text password with the random salt and multiple iterations and then Base64-encode the value (requires less space than Hex)
    final String hashedPasswordBase64 = new SimpleHash(KillbillCredentialsMatcher.HASH_ALGORITHM_NAME, entity.getApiSecret(), salt, securityConfig.getShiroNbHashIterations()).toBase64();
    transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {

        @Override
        public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
            final TenantModelDao tenantModelDaoWithSecret = new TenantModelDao(entity.getId(), context.getCreatedDate(), context.getUpdatedDate(), entity.getExternalKey(), entity.getApiKey(), hashedPasswordBase64, salt.toBase64());
            entitySqlDaoWrapperFactory.become(TenantSqlDao.class).create(tenantModelDaoWithSecret, context);
            return null;
        }
    });
}
Also used : SimpleHash(org.apache.shiro.crypto.hash.SimpleHash) ByteSource(org.apache.shiro.util.ByteSource) EntitySqlDaoWrapperFactory(org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) EntityPersistenceException(org.killbill.billing.entity.EntityPersistenceException)

Example 8 with TenantApiException

use of org.killbill.billing.tenant.api.TenantApiException in project killbill by killbill.

the class TestDefaultTenantUserApi method testCreateTenantWithExternalKeyOverLimit.

@Test(groups = "slow", description = "Test Tenant creation with External Key over limit")
public void testCreateTenantWithExternalKeyOverLimit() throws Exception {
    final TenantData tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,.", "TTR445ee2", "dskjhfs^^54R");
    try {
        tenantUserApi.createTenant(tenantdata, callContext);
        Assert.fail();
    } catch (final TenantApiException e) {
        Assert.assertEquals(e.getCode(), ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED.getCode());
    }
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) TenantData(org.killbill.billing.tenant.api.TenantData) Test(org.testng.annotations.Test)

Aggregations

TenantApiException (org.killbill.billing.tenant.api.TenantApiException)8 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)5 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)3 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)3 IOException (java.io.IOException)2 CatalogUpdater (org.killbill.billing.catalog.CatalogUpdater)2 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JAXBException (javax.xml.bind.JAXBException)1 TransformerException (javax.xml.transform.TransformerException)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 SimpleHash (org.apache.shiro.crypto.hash.SimpleHash)1 ByteSource (org.apache.shiro.util.ByteSource)1