/** * Gets a client for the Credentials service. * * @param tenantId The tenant to get the client for. * @return A future containing the client. */ protected final Future<CredentialsClient> getCredentialsClient(final String tenantId) { if (credentialsServiceClient == null) { return Future.failedFuture(new IllegalStateException("no credentials client set")); } else { return credentialsServiceClient.getOrCreateCredentialsClient(tenantId); } }
/** * Gets a client for the Credentials service. * * @param tenantId The tenant to get the client for. * @return A future containing the client. */ protected final Future<CredentialsClient> getCredentialsClient(final String tenantId) { if (credentialsServiceClient == null) { return Future.failedFuture(new IllegalStateException("no credentials client set")); } else { return credentialsServiceClient.getOrCreateCredentialsClient(tenantId); } }
/** * Sets up the fixture. */ @Before public void setUp() { credentialsClient = mock(CredentialsClient.class); when(credentialsClient.isOpen()).thenReturn(Boolean.TRUE); honoClient = mock(HonoClient.class); when(honoClient.getOrCreateCredentialsClient(anyString())).thenReturn(Future.succeededFuture(credentialsClient)); provider = getProvider(getDeviceCredentials("type", "TENANT", "user"), NoopTracerFactory.create()); }
/** * Get pre-shared-key for device from credentials service. * <p> * On success, add hono device to cache. * * @param handshakeIdentity pre-shared-key identity of device. * @return future with pre-shared-key. */ protected final Future<byte[]> getSharedKeyForDevice(final PreSharedKeyDeviceIdentity handshakeIdentity) { Objects.requireNonNull(handshakeIdentity); return credentialsServiceClient.getOrCreateCredentialsClient(handshakeIdentity.getTenantId()) .compose(client -> client.get(handshakeIdentity.getType(), handshakeIdentity.getAuthId())) .compose((credentials) -> { final byte[] key = getCandidateKey(credentials); if (key != null) { devices.put(handshakeIdentity, new Device(handshakeIdentity.getTenantId(), credentials.getDeviceId())); return Future.succeededFuture(key); } else { return Future.failedFuture("secret key missing!"); } }); }
/** * Sets up the fixture. */ @Before public void setUp() { credentialsOnRecord = new CredentialsObject() .setAuthId("device") .setDeviceId("4711") .setType(CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD) .setEnabled(true); credentialsClient = mock(CredentialsClient.class); when(credentialsClient.get(anyString(), anyString(), any(JsonObject.class), any())).thenReturn(Future.succeededFuture(credentialsOnRecord)); credentialsServiceClient = mock(HonoClient.class); when(credentialsServiceClient.getOrCreateCredentialsClient(anyString())).thenReturn(Future.succeededFuture(credentialsClient)); pwdEncoder = mock(HonoPasswordEncoder.class); when(pwdEncoder.matches(anyString(), any(JsonObject.class))).thenReturn(true); provider = new UsernamePasswordAuthProvider(credentialsServiceClient, pwdEncoder, new ServiceConfigProperties(), NoopTracerFactory.create()); }