use of io.micronaut.session.Session in project micronaut-multitenancy by micronaut-projects.
the class SessionTenantResolver method resolveTenantIdentifier.
@Override
@NonNull
public Serializable resolveTenantIdentifier(@NonNull @NotNull HttpRequest<?> request) throws TenantNotFoundException {
if (this.attribute == null) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, because session attribute name is not set");
}
Optional<Session> opt = request.getAttributes().get(HttpSessionFilter.SESSION_ATTRIBUTE, Session.class);
if (!opt.isPresent()) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, if session not present");
}
Session session = opt.get();
Optional<Object> tenantId = session.get(attribute);
if (!tenantId.isPresent()) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, if session attribute (" + attribute + ") not present");
}
if (!(tenantId.get() instanceof Serializable)) {
throw new TenantNotFoundException("Tenant was resolved from HTTP Session, but it is not serializable");
}
return (Serializable) tenantId.get();
}
Aggregations