本文整理了Java中fathom.realm.Account.isGuest()
方法的一些代码示例,展示了Account.isGuest()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Account.isGuest()
方法的具体详情如下:
包路径:fathom.realm.Account
类名称: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;
}
内容来源于网络,如有侵权,请联系作者删除!