Search in sources :

Example 1 with SpringBasedHonoPasswordEncoder

use of org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder in project hono by eclipse.

the class AbstractJdbcRegistryTest method startDevices.

@BeforeEach
void startDevices(final Vertx vertx) throws IOException, SQLException {
    final var jdbc = resolveJdbcProperties();
    try (var connection = DriverManager.getConnection(jdbc.getUrl(), jdbc.getUsername(), jdbc.getPassword());
        var script = Files.newBufferedReader(EXAMPLE_SQL_BASE.resolve("02-create.devices.sql"))) {
        // pre-create database
        RunScript.execute(connection, script);
    }
    properties = new DeviceServiceProperties();
    this.credentialsAdapter = new CredentialsServiceImpl(DeviceStores.adapterStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
    this.registrationAdapter = new RegistrationServiceImpl(DeviceStores.adapterStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), new NoOpSchemaCreator());
    this.credentialsManagement = new CredentialsManagementServiceImpl(vertx, new SpringBasedHonoPasswordEncoder(properties.getMaxBcryptCostfactor()), DeviceStores.managementStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
    this.registrationManagement = new DeviceManagementServiceImpl(vertx, DeviceStores.managementStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
    tenantInformationService = mock(TenantInformationService.class);
    when(tenantInformationService.getTenant(anyString(), any())).thenReturn(Future.succeededFuture(new Tenant()));
    when(tenantInformationService.tenantExists(anyString(), any())).thenAnswer(invocation -> {
        return Future.succeededFuture(OperationResult.ok(HttpURLConnection.HTTP_OK, TenantKey.from(invocation.getArgument(0)), Optional.empty(), Optional.empty()));
    });
    registrationManagement.setTenantInformationService(tenantInformationService);
    credentialsManagement.setTenantInformationService(tenantInformationService);
}
Also used : Tenant(org.eclipse.hono.service.management.tenant.Tenant) SpringBasedHonoPasswordEncoder(org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder) TenantInformationService(org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService) DeviceServiceProperties(org.eclipse.hono.deviceregistry.jdbc.config.DeviceServiceProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SpringBasedHonoPasswordEncoder

use of org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder in project hono by eclipse.

the class ManagementServicesProducer method credentialsManagementService.

/**
 * Creates a JDBC based credentials management service.
 *
 * @param devicesManagementStore The data store for accessing credentials data.
 * @param deviceServiceOptions The device management service configuration.
 * @param tenantInformationService The service for retrieving tenant information.
 * @return The service.
 */
@Produces
@Singleton
public CredentialsManagementService credentialsManagementService(final TableManagementStore devicesManagementStore, final DeviceServiceOptions deviceServiceOptions, final TenantInformationService tenantInformationService) {
    final var service = new CredentialsManagementServiceImpl(vertx, new SpringBasedHonoPasswordEncoder(deviceServiceOptions.maxBcryptCostFactor()), devicesManagementStore, deviceServiceOptions);
    service.setTenantInformationService(tenantInformationService);
    return service;
}
Also used : SpringBasedHonoPasswordEncoder(org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder) CredentialsManagementServiceImpl(org.eclipse.hono.deviceregistry.jdbc.impl.CredentialsManagementServiceImpl) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 3 with SpringBasedHonoPasswordEncoder

use of org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder in project hono by eclipse.

the class ManagementServicesProducer method credentialsManagementService.

/**
 * Creates a Mongo DB based credentials management service.
 *
 * @param credentialsDao The DAO for accessing credentials data.
 * @param tenantInformationService The service for retrieving tenant information.
 * @return The service.
 */
@Produces
@Singleton
public CredentialsManagementService credentialsManagementService(final CredentialsDao credentialsDao, final TenantInformationService tenantInformationService) {
    final var service = new MongoDbBasedCredentialsManagementService(vertx, credentialsDao, credentialsServiceProperties, new SpringBasedHonoPasswordEncoder(credentialsServiceProperties.getMaxBcryptCostFactor()));
    service.setTenantInformationService(tenantInformationService);
    return service;
}
Also used : SpringBasedHonoPasswordEncoder(org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder) MongoDbBasedCredentialsManagementService(org.eclipse.hono.deviceregistry.mongodb.service.MongoDbBasedCredentialsManagementService) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 4 with SpringBasedHonoPasswordEncoder

use of org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder in project hono by eclipse.

the class Credentials method createPasswordSecret.

/**
 * Create a new password secret.
 *
 * @param password The password to use.
 * @param bcryptCostFactor The cost factor to use for creating a bcrypt password hash.
 * @return The password secret instance.
 */
public static PasswordSecret createPasswordSecret(final String password, final OptionalInt bcryptCostFactor) {
    final SpringBasedHonoPasswordEncoder encoder = new SpringBasedHonoPasswordEncoder(bcryptCostFactor.orElse(SpringBasedHonoPasswordEncoder.DEFAULT_BCRYPT_STRENGTH));
    final EncodedPassword encodedPwd = EncodedPassword.fromHonoSecret(encoder.encode(password));
    final PasswordSecret s = new PasswordSecret();
    s.setHashFunction(encodedPwd.hashFunction);
    if (encodedPwd.salt != null) {
        s.setSalt(Base64.getEncoder().encodeToString(encodedPwd.salt));
    }
    s.setPasswordHash(encodedPwd.password);
    return s;
}
Also used : SpringBasedHonoPasswordEncoder(org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder) EncodedPassword(org.eclipse.hono.auth.EncodedPassword)

Aggregations

SpringBasedHonoPasswordEncoder (org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder)4 Produces (javax.enterprise.inject.Produces)2 Singleton (javax.inject.Singleton)2 EncodedPassword (org.eclipse.hono.auth.EncodedPassword)1 DeviceServiceProperties (org.eclipse.hono.deviceregistry.jdbc.config.DeviceServiceProperties)1 CredentialsManagementServiceImpl (org.eclipse.hono.deviceregistry.jdbc.impl.CredentialsManagementServiceImpl)1 MongoDbBasedCredentialsManagementService (org.eclipse.hono.deviceregistry.mongodb.service.MongoDbBasedCredentialsManagementService)1 TenantInformationService (org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService)1 Tenant (org.eclipse.hono.service.management.tenant.Tenant)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1