Search in sources :

Example 6 with ByteSource

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;
        }
    });
}
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)

Aggregations

ByteSource (org.apache.shiro.util.ByteSource)6 SimpleHash (org.apache.shiro.crypto.hash.SimpleHash)3 DateTime (org.joda.time.DateTime)2 SecurityApiException (org.killbill.billing.security.SecurityApiException)2 Handle (org.skife.jdbi.v2.Handle)2 TransactionStatus (org.skife.jdbi.v2.TransactionStatus)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 Subject (org.apache.shiro.subject.Subject)1 EntityPersistenceException (org.killbill.billing.entity.EntityPersistenceException)1 TenantApiException (org.killbill.billing.tenant.api.TenantApiException)1 EntitySqlDaoWrapperFactory (org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory)1