本文整理了Java中fathom.realm.Account.getUsername()
方法的一些代码示例,展示了Account.getUsername()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Account.getUsername()
方法的具体详情如下:
包路径:fathom.realm.Account
类名称:Account
方法名:getUsername
暂无
代码示例来源:origin: gitblit/fathom
protected void cacheAccount(Account account) {
if (accountCache != null) {
accountCache.put(account.getUsername(), account);
}
}
代码示例来源:origin: gitblit/fathom
protected void cacheAccount(Account account) {
if (accountCache != null) {
accountCache.put(account.getUsername(), account);
}
}
代码示例来源:origin: com.gitblit.fathom/fathom-security
public Account addAccount(Account account) {
accounts.putIfAbsent(account.getUsername(), account);
return account;
}
代码示例来源:origin: com.gitblit.fathom/fathom-security
protected void cacheAccount(Account account) {
if (accountCache != null) {
accountCache.put(account.getUsername(), account);
}
}
代码示例来源:origin: gitblit/fathom
public Account addAccount(Account account) {
accounts.putIfAbsent(account.getUsername(), account);
return account;
}
代码示例来源: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: gitblit/fathom
/**
* Set the admin attribute from group memberships retrieved from Windows.
*
* @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: gitblit/fathom
/**
* 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-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: 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: 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: 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;
}
代码示例来源: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-security-ldap
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) {
String accountDN = accountSearchResult.getDN();
String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN));
groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername()));
// Fill in attributes into groupMemberPattern
for (Attribute attribute : accountSearchResult.getAttributes()) {
groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue()));
}
SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn"));
if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) {
for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) {
SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i);
String roleName = groupEntry.getAttribute("cn").getValue();
account.getAuthorizations().addRole(roleName);
}
}
}
代码示例来源:origin: gitblit/fathom
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) {
String accountDN = accountSearchResult.getDN();
String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN));
groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername()));
// Fill in attributes into groupMemberPattern
for (Attribute attribute : accountSearchResult.getAttributes()) {
groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue()));
}
SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn"));
if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) {
for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) {
SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i);
String roleName = groupEntry.getAttribute("cn").getValue();
account.getAuthorizations().addRole(roleName);
}
}
}
代码示例来源:origin: com.gitblit.fathom/fathom-security
public Account authenticate(StandardCredentials requestCredentials) {
if (hasAccount(requestCredentials.getUsername())) {
Account storedAccount = getAccount(requestCredentials.getUsername());
StandardCredentials storedCredentials = (StandardCredentials) storedAccount.getCredentials();
if (Strings.isNullOrEmpty(storedCredentials.getPassword())) {
log.debug("Account '{}' in '{}' has no password and may not be used for authentication",
storedAccount.getUsername(), getRealmName());
return null;
}
if (validatePassword(requestCredentials, storedCredentials)) {
log.debug("Authentication succeeded for '{}' against '{}'",
requestCredentials.getUsername(), getRealmName());
return storedAccount;
} else {
log.debug("Authentication failed for '{}' against '{}'",
requestCredentials.getUsername(), getRealmName());
}
} else {
log.debug("Unknown account '{}' in the '{}' realm", requestCredentials.getUsername(), getRealmName());
}
return null;
}
代码示例来源: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
public Account authenticate(StandardCredentials requestCredentials) {
if (hasAccount(requestCredentials.getUsername())) {
Account storedAccount = getAccount(requestCredentials.getUsername());
StandardCredentials storedCredentials = (StandardCredentials) storedAccount.getCredentials();
if (Strings.isNullOrEmpty(storedCredentials.getPassword())) {
log.debug("Account '{}' in '{}' has no password and may not be used for authentication",
storedAccount.getUsername(), getRealmName());
return null;
}
if (validatePassword(requestCredentials, storedCredentials)) {
log.debug("Authentication succeeded for '{}' against '{}'",
requestCredentials.getUsername(), getRealmName());
return storedAccount;
} else {
log.debug("Authentication failed for '{}' against '{}'",
requestCredentials.getUsername(), getRealmName());
}
} else {
log.debug("Unknown account '{}' in the '{}' realm", requestCredentials.getUsername(), getRealmName());
}
return null;
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!