Search in sources :

Example 21 with EntitySqlDaoWrapperFactory

use of org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory 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(false, 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());
            final TenantSqlDao tenantSqlDao = entitySqlDaoWrapperFactory.become(TenantSqlDao.class);
            createAndRefresh(tenantSqlDao, 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 22 with EntitySqlDaoWrapperFactory

use of org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory in project killbill by killbill.

the class DefaultAuditDao method doGetAuditLogsViaHistoryForId.

private List<AuditLog> doGetAuditLogsViaHistoryForId(final TableName tableName, final UUID objectId, final AuditLevel auditLevel, final InternalTenantContext context) {
    final TableName historyTableName = tableName.getHistoryTableName();
    if (historyTableName == null) {
        throw new IllegalStateException("History table shouldn't be null for " + tableName);
    }
    final Long targetRecordId = dbRouter.onDemand(true).getRecordIdFromObject(objectId.toString(), tableName.getTableName());
    final List<AuditLog> allAuditLogs = transactionalSqlDao.execute(true, new EntitySqlDaoTransactionWrapper<List<AuditLog>>() {

        @Override
        public List<AuditLog> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
            final List<AuditLogModelDao> auditLogsViaHistoryForTargetRecordId = entitySqlDaoWrapperFactory.become(EntitySqlDao.class).getAuditLogsViaHistoryForTargetRecordId(historyTableName.name(), historyTableName.getTableName().toLowerCase(), targetRecordId, context);
            return buildAuditLogsFromModelDao(auditLogsViaHistoryForTargetRecordId, tableName.getObjectType(), objectId);
        }
    });
    return filterAuditLogs(auditLevel, allAuditLogs);
}
Also used : TableName(org.killbill.billing.util.dao.TableName) EntitySqlDaoWrapperFactory(org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) AuditLog(org.killbill.billing.util.audit.AuditLog)

Aggregations

EntitySqlDaoWrapperFactory (org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory)22 EntityPersistenceException (org.killbill.billing.entity.EntityPersistenceException)14 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)13 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)12 UUID (java.util.UUID)12 ArrayList (java.util.ArrayList)10 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)9 IOException (java.io.IOException)8 LinkedList (java.util.LinkedList)8 SubscriptionApiException (org.killbill.billing.entitlement.api.SubscriptionApiException)8 LocalDate (org.joda.time.LocalDate)6 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)6 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)6 Predicate (com.google.common.base.Predicate)5 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)5 Tag (org.killbill.billing.util.tag.Tag)5 Test (org.testng.annotations.Test)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4