fathom.realm.Account.isGuest()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中fathom.realm.Account.isGuest()方法的一些代码示例,展示了Account.isGuest()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Account.isGuest()方法的具体详情如下:
包路径:fathom.realm.Account
类名称:Account
方法名:isGuest

Account.isGuest介绍

[英]Returns true if this Account is the GUEST account.
[中]如果此帐户是来宾帐户,则返回true。

代码示例

代码示例来源:origin: com.gitblit.fathom/fathom-security

/**
 * Returns {@code true} if this Account is authenticated.
 *
 * @return true if this Account is authenticated.
 */
public boolean isAuthenticated() {
  return !isGuest();
}

代码示例来源:origin: gitblit/fathom

/**
 * Returns {@code true} if this Account is authenticated.
 *
 * @return true if this Account is authenticated.
 */
public boolean isAuthenticated() {
  return !isGuest();
}

代码示例来源:origin: gitblit/fathom

/**
 * Ensures this Account is the Guest account.
 * <p>
 *
 * @throws fathom.authc.AuthenticationException if the Account is not the Guest account.
 */
public void checkGuest() throws AuthenticationException {
  if (!isGuest()) {
    throw new AuthorizationException("'{}' is not the Guest account", toString());
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-security

/**
 * Ensures this Account is the Guest account.
 * <p>
 *
 * @throws fathom.authc.AuthenticationException if the Account is not the Guest account.
 */
public void checkGuest() throws AuthenticationException {
  if (!isGuest()) {
    throw new AuthorizationException("'{}' is not the Guest account", toString());
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-xmlrpc

protected void authenticate(Context context) {
    Account session = context.getSession(AuthConstants.ACCOUNT_ATTRIBUTE);
    Account local = context.getLocal(AuthConstants.ACCOUNT_ATTRIBUTE);
    Account account = Optional.fromNullable(session).or(Optional.fromNullable(local).or(Account.GUEST));

    if (account.isGuest()) {
      String authorization = context.getRequest().getHeader("Authorization");
      if (!Strings.isNullOrEmpty(authorization)) {
        if (authorization.toLowerCase().startsWith("token")) {
          String packet = authorization.substring("token".length()).trim();
          TokenCredentials credentials = new TokenCredentials(packet);
          account = securityManager.authenticate(credentials);
        } else if (authorization.toLowerCase().startsWith("basic")) {
          String packet = authorization.substring("basic".length()).trim();
          String credentials1 = new String(Base64.getDecoder().decode(packet), StandardCharsets.UTF_8);
          String[] values1 = credentials1.split(":", 2);
          String username = values1[0];
          String password = values1[1];
          StandardCredentials authenticationToken = new StandardCredentials(username, password);
          account = securityManager.authenticate(authenticationToken);
        }
      }
    }

    account = Optional.fromNullable(account).or(Account.GUEST);
    context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
  }
}

代码示例来源:origin: gitblit/fathom

protected void authenticate(Context context) {
    Account session = context.getSession(AuthConstants.ACCOUNT_ATTRIBUTE);
    Account local = context.getLocal(AuthConstants.ACCOUNT_ATTRIBUTE);
    Account account = Optional.fromNullable(session).or(Optional.fromNullable(local).or(Account.GUEST));

    if (account.isGuest()) {
      String authorization = context.getRequest().getHeader("Authorization");
      if (!Strings.isNullOrEmpty(authorization)) {
        if (authorization.toLowerCase().startsWith("token")) {
          String packet = authorization.substring("token".length()).trim();
          TokenCredentials credentials = new TokenCredentials(packet);
          account = securityManager.authenticate(credentials);
        } else if (authorization.toLowerCase().startsWith("basic")) {
          String packet = authorization.substring("basic".length()).trim();
          String credentials1 = new String(Base64.getDecoder().decode(packet), StandardCharsets.UTF_8);
          String[] values1 = credentials1.split(":", 2);
          String username = values1[0];
          String password = values1[1];
          StandardCredentials authenticationToken = new StandardCredentials(username, password);
          account = securityManager.authenticate(authenticationToken);
        }
      }
    }

    account = Optional.fromNullable(account).or(Account.GUEST);
    context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-rest-security

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  RequireToken requireToken = ClassUtil.getAnnotation(invocation.getMethod(), RequireToken.class);
  String tokenName = requireToken.value();
  Context context = RouteDispatcher.getRouteContext();
  // extract the named token from a header or a query parameter
  String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
  token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));
  if (Strings.isNullOrEmpty(token)) {
    throw new AuthorizationException("Missing '{}' token", tokenName);
  }
  Account account = getAccount();
  if (account.isGuest()) {
    // authenticate by token
    TokenCredentials credentials = new TokenCredentials(token);
    account = securityManager.get().authenticate(credentials);
    if (account == null) {
      throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
    }
    context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
    log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
  } else {
    // validate token
    account.checkToken(token);
  }
  return invocation.proceed();
}

代码示例来源:origin: gitblit/fathom

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  RequireToken requireToken = ClassUtil.getAnnotation(invocation.getMethod(), RequireToken.class);
  String tokenName = requireToken.value();
  Context context = RouteDispatcher.getRouteContext();
  // extract the named token from a header or a query parameter
  String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
  token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));
  if (Strings.isNullOrEmpty(token)) {
    throw new AuthorizationException("Missing '{}' token", tokenName);
  }
  Account account = getAccount();
  if (account.isGuest()) {
    // authenticate by token
    TokenCredentials credentials = new TokenCredentials(token);
    account = securityManager.get().authenticate(credentials);
    if (account == null) {
      throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
    }
    context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
    log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
  } else {
    // validate token
    account.checkToken(token);
  }
  return invocation.proceed();
}

代码示例来源:origin: com.gitblit.fathom/fathom-rest-security

protected Account checkRequireToken(Method method) {
  Account account = getAccount();
  RequireToken requireToken = ClassUtil.getAnnotation(method, RequireToken.class);
  if (requireToken != null) {
    String tokenName = requireToken.value();
    Context context = RouteDispatcher.getRouteContext();
    // extract the named token from a header or a query parameter
    String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
    token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));
    if (Strings.isNullOrEmpty(token)) {
      throw new AuthorizationException("Missing '{}' token", tokenName);
    }
    if (account.isGuest()) {
      // authenticate by token
      TokenCredentials credentials = new TokenCredentials(token);
      account = securityManager.get().authenticate(credentials);
      if (account == null) {
        throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
      }
      context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
      log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
    } else {
      // validate token
      account.checkToken(token);
    }
  }
  return account;
}

代码示例来源:origin: gitblit/fathom

protected Account checkRequireToken(Method method) {
  Account account = getAccount();
  RequireToken requireToken = ClassUtil.getAnnotation(method, RequireToken.class);
  if (requireToken != null) {
    String tokenName = requireToken.value();
    Context context = RouteDispatcher.getRouteContext();
    // extract the named token from a header or a query parameter
    String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
    token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));
    if (Strings.isNullOrEmpty(token)) {
      throw new AuthorizationException("Missing '{}' token", tokenName);
    }
    if (account.isGuest()) {
      // authenticate by token
      TokenCredentials credentials = new TokenCredentials(token);
      account = securityManager.get().authenticate(credentials);
      if (account == null) {
        throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
      }
      context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
      log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
    } else {
      // validate token
      account.checkToken(token);
    }
  }
  return account;
}

相关文章