Skip to content

Commit

Permalink
Added builtin function to test if is logged in based on session inter…
Browse files Browse the repository at this point in the history
…ceptor instance
  • Loading branch information
t-burch authored and rrayst committed Feb 6, 2024
1 parent bf5c9b6 commit 8325b7c
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
package com.predic8.membrane.core.lang.spel.functions;

import com.predic8.membrane.core.http.Header;
import com.predic8.membrane.core.interceptor.AbstractInterceptorWithSession;
import com.predic8.membrane.core.lang.spel.ExchangeEvaluationContext;
import org.apache.http.auth.AUTH;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.function.Predicate;

import static com.predic8.membrane.core.http.Header.AUTHORIZATION;
import static com.predic8.membrane.core.interceptor.apikey.ApiKeysInterceptor.SCOPES;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

/**
Expand All @@ -33,6 +37,17 @@
* The ExchangeEvaluationContext provides a specialized Membrane SpEL context, enabling access to the Exchange and other relevant data.
*/
public class BuiltInFunctions {
private static final Logger log = LoggerFactory.getLogger(ExchangeEvaluationContext.class.getName());

public static boolean isLoggedIn(String beanName, ExchangeEvaluationContext ctx) {
try {
return ((AbstractInterceptorWithSession) requireNonNull(ctx.getBeanResolver()).resolve(ctx, beanName))
.getSessionManager().getSession(ctx.getExchange()).isVerified();
} catch (Exception e) {
log.info("Failed to resolve bean with name '" + beanName + "'");
return false;
}
}

public static boolean isBearerAuthorization(ExchangeEvaluationContext ctx) {
return ctx.getExchange().getRequest().getHeader().contains(AUTHORIZATION)
Expand Down

0 comments on commit 8325b7c

Please sign in to comment.