本文整理了Java中fathom.realm.Account
类的一些代码示例,展示了Account
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Account
类的具体详情如下:
包路径:fathom.realm.Account
类名称:Account
[英]Account represents Credentials and Authorizations. This class is partially based on Apache Shiro Subject.
[中]帐户表示凭据和授权。这个类部分基于ApacheShiro主题。
代码示例来源:origin: com.gitblit.fathom/fathom-security
if (realm.canAuthenticate(authenticationToken)) {
Account account = realm.authenticate(authenticationToken);
if (account != null && !account.isDisabled()) {
authenticatedAccount = new Account(account.getName(), account.getCredentials().sanitize());
break;
.filter(realm -> realm.hasAccount(aggregateAccount.getUsername()))
.map(realm -> realm.getAccount(aggregateAccount.getUsername()))
.filter(account -> account.isEnabled())
.forEach(account -> {
if (Strings.isNullOrEmpty(aggregateAccount.getName())) {
aggregateAccount.setName(account.getName());
aggregateAccount.addEmailAddresses(account.getEmailAddresses());
aggregateAccount.addTokens(account.getTokens());
aggregateAccount.getAuthorizations()
.addRoles(account.getAuthorizations().getRoles())
.addPermissions(account.getAuthorizations().getPermissions());
});
代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap
/**
* Set the admin attribute from group memberships retrieved from LDAP.
*
* @param account
*/
private void setAdminAttribute(Account account) {
if (adminGroups != null) {
for (String adminGroup : adminGroups) {
if (adminGroup.startsWith("@") && account.getUsername().equalsIgnoreCase(adminGroup.substring(1))) {
// admin user
account.getAuthorizations().addPermission("*");
} else if (account.hasRole(adminGroup)) {
// admin role
account.getAuthorizations().addPermission("*");
}
}
}
}
代码示例来源: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: 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-security
/**
* Asserts this Account has the specified role by returning quietly if they do or throwing an
* {@link fathom.authz.AuthorizationException} if they do not.
*
* @param roleIdentifier the application-specific role identifier (usually a role id or role name ).
* @throws fathom.authz.AuthorizationException if this Account does not have the role.
*/
public void checkRole(String roleIdentifier) throws AuthorizationException {
if (!hasRole(roleIdentifier)) {
throw new AuthorizationException("'{}' does not have the role '{}'", toString(), roleIdentifier);
}
}
代码示例来源:origin: com.gitblit.fathom/fathom-security
Account account = new Account(name, credentials);
account.addEmailAddresses(accountConfig.getStringList("emailAddresses"));
account.addTokens(accountConfig.getStringList("tokens"));
for (String token : account.getTokens()) {
if (tokens.containsKey(token)) {
String otherAccount = tokens.get(token).getUsername();
log.error("Token collision: {} has the same token as {}", account.getUsername(), otherAccount);
} else {
tokens.put(token, account);
account.setDisabled();
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
account.getAuthorizations().addPermission(permission);
代码示例来源:origin: com.gitblit.fathom/fathom-security-jdbc
account = new Account(name, new StandardCredentials(username, password));
String value = rs.getString(emailMapping);
Set<String> addresses = toSet(value, COMMA_SEMI_COLON_DELIMITER);
account.addEmailAddresses(addresses);
Set<String> permissions = toSet(value, SEMI_COLON_DELIMITER);
for (String permission : permissions) {
account.getAuthorizations().addPermission(permission);
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
代码示例来源:origin: gitblit/fathom
@Override
public Account authenticate(AuthenticationToken authenticationToken) {
KeycloakToken keycloakToken = (KeycloakToken) authenticationToken;
Account account = new Account(keycloakToken.getUsername(), keycloakToken);
AccessToken accessToken = keycloakToken.getToken();
account.setName(accessToken.getName());
account.addEmailAddress(accessToken.getEmail());
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
代码示例来源:origin: com.gitblit.fathom/fathom-security-jdbc
private void setAuthorizationsByQuery(Connection conn, Account account) throws SQLException {
// Retrieve roles and permissions from database
Map<String, Role> declaredRoles = getDefinedRoles(conn);
Set<String> roles = getRolesByQuery(conn, account.getUsername());
for (String role : roles) {
if (declaredRoles.containsKey(role)) {
Role declaredRole = declaredRoles.get(role);
account.getAuthorizations().addRole(declaredRole);
} else {
account.getAuthorizations().addRole(role);
}
}
Set<String> permissions = getPermissionsByQuery(conn, account.getUsername());
for (String permission : permissions) {
account.getAuthorizations().addPermission(permission);
}
}
代码示例来源: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
Account account = new Account(name, new StandardCredentials(username, password));
account.getAuthorizations().addRole(group.getFqn());
代码示例来源:origin: com.gitblit.fathom/fathom-security-jdbc
@Override
public Account authenticate(final String username, final String password) {
try (Connection conn = dataSource.getConnection()) {
Account account = getAccount(conn, username);
if (account == null) {
log.debug("No account found for '{}' in '{}'", username, getRealmName());
return null;
}
StandardCredentials storedCredentials = (StandardCredentials) account.getCredentials();
if (Strings.isNullOrEmpty(storedCredentials.getPassword())) {
log.debug("Account '{}' in '{}' has no password and may not be used for authentication",
account.getUsername(), getRealmName());
return null;
}
StandardCredentials requestCredentials = new StandardCredentials(username, password);
if (validatePassword(requestCredentials, storedCredentials)) {
log.debug("Authentication succeeded for '{}' against '{}'", username, getRealmName());
setAuthorizationsByQuery(conn, account);
cacheAccount(account);
return account;
} else {
log.debug("Authentication failed for '{}' against '{}'", username, getRealmName());
}
} catch (SQLException e) {
log.error("There was an SQL error while authenticating '{}'", username, e);
}
return null;
}
代码示例来源:origin: com.gitblit.fathom/fathom-security
public Account addAccount(String name, String username, String password) {
StandardCredentials credentials = new StandardCredentials(username, password);
Account account = new Account(name, credentials);
return addAccount(account);
}
代码示例来源:origin: gitblit/fathom
protected void cacheAccount(Account account) {
if (accountCache != null) {
accountCache.put(account.getUsername(), account);
}
}
代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap
pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue());
account.setName(pattern);
} else {
account.setName(attribute.getValue());
pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue());
account.addEmailAddress(pattern);
} else {
account.addEmailAddress(attribute.getValue());
代码示例来源:origin: gitblit/fathom
Account account = new Account(name, credentials);
account.addEmailAddresses(accountConfig.getStringList("emailAddresses"));
account.addTokens(accountConfig.getStringList("tokens"));
for (String token : account.getTokens()) {
if (tokens.containsKey(token)) {
String otherAccount = tokens.get(token).getUsername();
log.error("Token collision: {} has the same token as {}", account.getUsername(), otherAccount);
} else {
tokens.put(token, account);
account.setDisabled();
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
account.getAuthorizations().addPermission(permission);
代码示例来源:origin: gitblit/fathom
account = new Account(name, new StandardCredentials(username, password));
String value = rs.getString(emailMapping);
Set<String> addresses = toSet(value, COMMA_SEMI_COLON_DELIMITER);
account.addEmailAddresses(addresses);
Set<String> permissions = toSet(value, SEMI_COLON_DELIMITER);
for (String permission : permissions) {
account.getAuthorizations().addPermission(permission);
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
代码示例来源:origin: gitblit/fathom
private void setAuthorizationsByQuery(Connection conn, Account account) throws SQLException {
// Retrieve roles and permissions from database
Map<String, Role> declaredRoles = getDefinedRoles(conn);
Set<String> roles = getRolesByQuery(conn, account.getUsername());
for (String role : roles) {
if (declaredRoles.containsKey(role)) {
Role declaredRole = declaredRoles.get(role);
account.getAuthorizations().addRole(declaredRole);
} else {
account.getAuthorizations().addRole(role);
}
}
Set<String> permissions = getPermissionsByQuery(conn, account.getUsername());
for (String permission : permissions) {
account.getAuthorizations().addPermission(permission);
}
}
代码示例来源: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: gitblit/fathom
@Override
public Account authenticate(final String username, final String password) {
try (Connection conn = dataSource.getConnection()) {
Account account = getAccount(conn, username);
if (account == null) {
log.debug("No account found for '{}' in '{}'", username, getRealmName());
return null;
}
StandardCredentials storedCredentials = (StandardCredentials) account.getCredentials();
if (Strings.isNullOrEmpty(storedCredentials.getPassword())) {
log.debug("Account '{}' in '{}' has no password and may not be used for authentication",
account.getUsername(), getRealmName());
return null;
}
StandardCredentials requestCredentials = new StandardCredentials(username, password);
if (validatePassword(requestCredentials, storedCredentials)) {
log.debug("Authentication succeeded for '{}' against '{}'", username, getRealmName());
setAuthorizationsByQuery(conn, account);
cacheAccount(account);
return account;
} else {
log.debug("Authentication failed for '{}' against '{}'", username, getRealmName());
}
} catch (SQLException e) {
log.error("There was an SQL error while authenticating '{}'", username, e);
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!