KULeuven-CCIS / idp-authn-jwt

Shibboleth IdP JWT authentication module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Null pointer exception when no cookie at all

psagne opened this issue · comments

I'm using your module to authenticate users in Shibboleth IdP with JWT tokens.
It works all really well, except when there is no cookie at all : the module throws a NullPointerException.

2018-05-16 07:38:44,671 - ERROR [net.shibboleth.idp.authn:-2] - Uncaught runtime exception
java.lang.NullPointerException: null
at java.util.Arrays.stream(Arrays.java:5004)
at be.kuleuven.ccis.shibboleth.idp.authn.impl.InitializeJWTContext.doExecute(InitializeJWTContext.java:65)
at net.shibboleth.idp.authn.AbstractAuthenticationAction.doExecute(AbstractAuthenticationAction.java:98)
at org.opensaml.profile.action.AbstractProfileAction.execute(AbstractProfileAction.java:117)
at net.shibboleth.idp.profile.AbstractProfileAction.doExecute(AbstractProfileAction.java:154)
at net.shibboleth.idp.profile.AbstractProfileAction.execute(AbstractProfileAction.java:126)
at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:77)
...

Simply adding a null check seems to fix this issue :

    Cookie jwtCookie = null;
    if (this.getHttpServletRequest().getCookies() != null) {
        jwtCookie = Arrays.stream(this.getHttpServletRequest().getCookies())
            .filter(x -> cookieName.equals(x.getName()))
            .findAny()
            .orElse(null);
    }
commented

Thank you for your contribution! The fix was added to 09be323.