create a more flexible interface for the creation of access tokens

Provide a AccessTokenBuilderFactory to simplify the creation of access tokens and a default implementation which is based on JWT. Added also an AccessTokenCookieIssuer to unify the creation of access token cookies. Removed old BearerTokenGenerator.
This commit is contained in:
Sebastian Sdorra
2017-01-17 14:40:50 +01:00
parent e7d6f50fd9
commit 2388cfd35d
15 changed files with 912 additions and 349 deletions

View File

@@ -33,7 +33,6 @@ package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import sonia.scm.plugin.Extension;
import sonia.scm.security.BearerAuthenticationToken;
@@ -41,6 +40,7 @@ import sonia.scm.security.BearerAuthenticationToken;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import sonia.scm.util.HttpUtil;
/**
* Creates an {@link BearerAuthenticationToken} from the {@link #COOKIE_NAME}
@@ -53,12 +53,6 @@ import javax.servlet.http.HttpServletRequest;
public class CookieBearerWebTokenGenerator implements WebTokenGenerator
{
/** cookie name */
@VisibleForTesting
static final String COOKIE_NAME = "X-Bearer-Token";
//~--- methods --------------------------------------------------------------
/**
* Creates an {@link BearerAuthenticationToken} from the {@link #COOKIE_NAME}
* cookie.
@@ -77,7 +71,7 @@ public class CookieBearerWebTokenGenerator implements WebTokenGenerator
{
for (Cookie cookie : cookies)
{
if (COOKIE_NAME.equals(cookie.getName()))
if (HttpUtil.COOKIE_BEARER_AUTHENTICATION.equals(cookie.getName()))
{
token = new BearerAuthenticationToken(cookie.getValue());