コード例 #1
0
  private void cacheUserInfo(CachableUserInfo user) {
    if (user == null || cache == null) {
      return;
    }

    try {
      cache.storeToken(user.getTenantId(), user, user.tokenTtl().intValue());
    } catch (IOException ex) {
      LOG.warn(
          "Unable to cache user token information: "
              + user.getUserId()
              + " Reason: "
              + ex.getMessage(),
          ex);
    }
  }
コード例 #2
0
  @Override
  public FilterDirector authenticate(HttpServletRequest request) {
    final FilterDirector filterDirector = new FilterDirectorImpl();
    filterDirector.setResponseStatus(HttpStatusCode.UNAUTHORIZED);
    filterDirector.setFilterAction(FilterAction.RETURN);

    final String authToken = request.getHeader(CommonHttpHeader.AUTH_TOKEN.toString());
    final ExtractorResult<Object> account = keyedRegexExtractor.extract(request.getRequestURI());
    CachableUserInfo user = null;

    if ((!StringUtilities.isBlank(authToken) && account != null)) {
      user = checkUserCache(account.getResult(), authToken);

      if (user == null) {
        try {
          user = authenticationService.validateToken(account.getResult(), authToken);
          cacheUserInfo(user);
        } catch (Exception ex) {
          LOG.error("Failure in auth: " + ex.getMessage(), ex);
          filterDirector.setResponseStatus(HttpStatusCode.INTERNAL_SERVER_ERROR);
        }
      }
    }

    Groups groups = null;
    if (user != null) {
      groups = authenticationService.getGroups(user.getUserId());
    }

    final AuthenticationHeaderManager headerManager =
        new AuthenticationHeaderManager(
            authToken,
            user,
            delegatable,
            filterDirector,
            account == null ? "" : account.getResult(),
            groups,
            request);
    headerManager.setFilterDirectorValues();

    return filterDirector;
  }