use of org.apache.shiro.util.ByteSource 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;
}
});
}
Aggregations