use of org.eclipse.hono.adapter.auth.device.DeviceCredentials in project hono by eclipse.
the class AbstractVertxBasedHttpProtocolAdapter method handleBeforeCredentialsValidation.
/**
* Handles any operations that should be invoked as part of the authentication process after the credentials got
* determined and before they get validated. Can be used to perform checks using the credentials and tenant
* information before the potentially expensive credentials validation is done
* <p>
* The default implementation updates the trace sampling priority in the execution context tracing span.
* It also verifies that the tenant provided via the credentials is enabled and that the adapter is enabled for
* that tenant, failing the returned future if either is not the case.
* <p>
* Subclasses should override this method in order to perform additional operations after calling this super method.
*
* @param credentials The credentials.
* @param executionContext The execution context, including the TenantObject.
* @return A future indicating the outcome of the operation. A failed future will fail the authentication attempt.
*/
protected Future<Void> handleBeforeCredentialsValidation(final DeviceCredentials credentials, final HttpContext executionContext) {
final String tenantId = credentials.getTenantId();
final String authId = credentials.getAuthId();
final Span span = Optional.ofNullable(executionContext.getTracingSpan()).orElseGet(() -> {
log.warn("handleBeforeCredentialsValidation: no span context set in httpContext");
return NoopSpan.INSTANCE;
});
return getTenantConfiguration(tenantId, span.context()).recover(t -> Future.failedFuture(CredentialsApiAuthProvider.mapNotFoundToBadCredentialsException(t))).map(tenantObject -> {
TracingHelper.setDeviceTags(span, tenantId, null, authId);
TenantTraceSamplingHelper.applyTraceSamplingPriority(tenantObject, authId, span);
return tenantObject;
}).compose(tenantObject -> isAdapterEnabled(tenantObject)).mapEmpty();
}
use of org.eclipse.hono.adapter.auth.device.DeviceCredentials in project hono by eclipse.
the class VertxBasedAmqpProtocolAdapter method handleBeforeCredentialsValidation.
/**
* Handles any operations that should be invoked as part of the authentication process after the credentials got
* determined and before they get validated. Can be used to perform checks using the credentials and tenant
* information before the potentially expensive credentials validation is done
* <p>
* The default implementation updates the trace sampling priority in the execution context tracing span.
* <p>
* Subclasses should override this method in order to perform additional operations after calling this super method.
*
* @param credentials The credentials.
* @param executionContext The execution context, including the TenantObject.
* @return A future indicating the outcome of the operation. A failed future will fail the authentication attempt.
*/
protected Future<Void> handleBeforeCredentialsValidation(final DeviceCredentials credentials, final SaslResponseContext executionContext) {
final String tenantId = credentials.getTenantId();
final Span span = executionContext.getTracingSpan();
final String authId = credentials.getAuthId();
return getTenantConfiguration(tenantId, span.context()).recover(t -> Future.failedFuture(CredentialsApiAuthProvider.mapNotFoundToBadCredentialsException(t))).compose(tenantObject -> {
TracingHelper.setDeviceTags(span, tenantId, null, authId);
final OptionalInt traceSamplingPriority = TenantTraceSamplingHelper.applyTraceSamplingPriority(tenantObject, authId, span);
executionContext.getProtonConnection().attachments().set(AmqpAdapterConstants.KEY_TRACE_SAMPLING_PRIORITY, OptionalInt.class, traceSamplingPriority);
return Future.succeededFuture();
});
}
use of org.eclipse.hono.adapter.auth.device.DeviceCredentials in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapter method handleBeforeCredentialsValidation.
/**
* Handles any operations that should be invoked as part of the authentication process after the credentials got
* determined and before they get validated. Can be used to perform checks using the credentials and tenant
* information before the potentially expensive credentials validation is done
* <p>
* The default implementation updates the trace sampling priority in the execution context tracing span.
* It also verifies that the tenant provided via the credentials is enabled and that the adapter is enabled for
* that tenant, failing the returned future if either is not the case.
* <p>
* Subclasses should override this method in order to perform additional operations after calling this super method.
*
* @param credentials The credentials.
* @param executionContext The execution context, including the TenantObject.
* @return A future indicating the outcome of the operation. A failed future will fail the authentication attempt.
*/
protected Future<Void> handleBeforeCredentialsValidation(final DeviceCredentials credentials, final MqttConnectContext executionContext) {
final String tenantId = credentials.getTenantId();
final Span span = executionContext.getTracingSpan();
final String authId = credentials.getAuthId();
return getTenantConfiguration(tenantId, span.context()).recover(t -> Future.failedFuture(CredentialsApiAuthProvider.mapNotFoundToBadCredentialsException(t))).map(tenantObject -> {
TracingHelper.setDeviceTags(span, tenantId, null, authId);
final OptionalInt traceSamplingPriority = TenantTraceSamplingHelper.applyTraceSamplingPriority(tenantObject, authId, span);
executionContext.setTraceSamplingPriority(traceSamplingPriority);
return tenantObject;
}).compose(this::isAdapterEnabled).mapEmpty();
}
Aggregations