Mercurial > hg > digilib
changeset 1507:8c7f1ef5a67f
added auth token in cookie. cookie name configurable as "auth-token-cookie".
author | robcast |
---|---|
date | Thu, 28 Apr 2016 19:40:47 +0200 |
parents | a693f487d860 |
children | b3d81e4581a7 e7e38e1f68df |
files | servlet/src/main/java/digilib/auth/OpenIdAuthnOps.java servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java |
diffstat | 2 files changed, 31 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/main/java/digilib/auth/OpenIdAuthnOps.java Thu Apr 28 19:07:49 2016 +0200 +++ b/servlet/src/main/java/digilib/auth/OpenIdAuthnOps.java Thu Apr 28 19:40:47 2016 +0200 @@ -31,6 +31,9 @@ import java.util.List; import java.util.Map; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + import org.apache.log4j.Logger; import org.jose4j.jwk.JsonWebKey; import org.jose4j.jwt.JwtClaims; @@ -43,6 +46,7 @@ import digilib.conf.DigilibConfiguration; import digilib.conf.DigilibRequest; +import digilib.conf.DigilibServletRequest; import digilib.util.XMLMapListLoader; /** @@ -75,6 +79,8 @@ protected JwtConsumer firstPassJwtConsumer; protected Map<String, JwtConsumer> idpJwtConsumers; protected Map<String, List<String>> idpRoles; + + protected String tokenCookieName; /* (non-Javadoc) @@ -164,6 +170,9 @@ continue; } } + + // set token cookie name + tokenCookieName = dlConfig.getAsString("auth-token-cookie"); } /* (non-Javadoc) @@ -179,10 +188,28 @@ */ @Override public List<String> getUserRoles(DigilibRequest request) throws AuthOpException { + /* + * try token parameter first + */ String id_token = request.getAsString("id_token"); if (id_token == null || id_token.isEmpty()) { - logger.error("Missing id token!"); - return null; + /* + * try token cookie next + */ + HttpServletRequest srvReq = ((DigilibServletRequest) request).getServletRequest(); + Cookie[] cookies = srvReq.getCookies(); + if (cookies != null) { + for (Cookie c : cookies) { + if (c.getName() == tokenCookieName) { + id_token = c.getValue(); + break; + } + } + } + if (id_token == null || id_token.isEmpty()) { + logger.error("Missing id token!"); + return null; + } } // the first JwtConsumer is just used to parse the JWT into a JwtContext object. try {
--- a/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java Thu Apr 28 19:07:49 2016 +0200 +++ b/servlet/src/main/java/digilib/conf/DigilibServletConfiguration.java Thu Apr 28 19:40:47 2016 +0200 @@ -169,7 +169,8 @@ newParameter("authzops-class", "digilib.auth.PathAuthzOps", null, 'f'); // DocuDirectory implementation newParameter("docudirectory-class", "digilib.io.BaseDirDocuDirectory", null, 'f'); - + // name of cookie with authentication token + newParameter("auth-token-cookie", "id_token", null, 'f'); } /**