本文整理汇总了Java中org.acegisecurity.userdetails.UsernameNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java UsernameNotFoundException类的具体用法?Java UsernameNotFoundException怎么用?Java UsernameNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsernameNotFoundException类属于org.acegisecurity.userdetails包,在下文中一共展示了UsernameNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
com.ramussoft.net.common.User user = getUserFactory().getUser(username);
if (user == null) {
throw new UsernameNotFoundException(MessageFormat.format(
"User {0} not found", username));
}
List<Group> list = user.getGroups();
GrantedAuthority[] arrayAuths = new GrantedAuthority[list.size() + 1];
for (int i = 0; i < list.size(); i++) {
arrayAuths[i] = new GrantedAuthorityImpl("ROLE_"
+ list.get(i).getName().toUpperCase());
}
arrayAuths[list.size()] = new GrantedAuthorityImpl("ROLE_USER");
return new User(user.getLogin(), user.getPassword(), true, true, true,
true, arrayAuths);
}
示例2: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
/**
* Locates the user based on the username.
*
* @param username The username presented to the {@link DaoAuthenticationProvider}
* @return A fully populated user record (never <code>null</code>)
* @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority.
* @throws DataAccessException If user could not be found for a repository-specific reason.
*/
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
User user = getUserByName(username);
if (user == null) {
throw new UsernameNotFoundException("User \"" + username + "\" was not found.");
}
String[] roles = userDao.getRolesForUser(username);
GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
for (int i = 0; i < roles.length; i++) {
authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase());
}
// If user is LDAP authenticated, disable user. The proper authentication should in that case
// be done by SubsonicLdapBindAuthenticator.
boolean enabled = !user.isLdapAuthenticated();
return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, true, authorities);
}
示例3: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(final String username)
throws UsernameNotFoundException, DataAccessException {
logger.finest("loadUserByUsername(" + username + ")");
try {
HtPasswdFile htpasswd = getHtPasswdFile();
String pwEntry = htpasswd.getPassword(username);
if (pwEntry == null)
throw new IllegalStateException("User does not exist");
return new User(username, "",
true, true, true, true,
getUserGroups(username));
} catch (Exception ex) {
String msg = String.format("Failed to load user '%s'", username);
throw new UsernameNotFoundException(msg, ex);
}
}
示例4: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
// Make sure AuthenticationManager Instance is available.
authenticationManagerInstance();
gov.nih.nci.security.authorization.domainobjects.User csmUser =
authorizationManagerInstance().getUser(username);
if (csmUser == null)
throw new UsernameNotFoundException("Unable to find user by the given user name");
// Get All GrantedAuthorities from CSM.
GrantedAuthority[] grantedAuthorities = getAuthorityCollection(csmUser.getUserId().toString());
UserDetails userDetails = new CSMUserDetails(grantedAuthorities, csmUser.getPassword(),csmUser
.getLoginName(), "Additional Data");
return userDetails;
}
示例5: authenticate
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
/**
* Authenticate a login attempt.
* This method is the heart of a {@link AbstractPasswordBasedSecurityRealm}.
* <p>
* <p>
* If the user name and the password pair matches, retrieve the information about this user and
* return it as a {@link UserDetails} object. {@link User} is a convenient
* implementation to use, but if your backend offers additional data, you may want to use your own subtype
* so that the rest of Hudson can use those additional information (such as e-mail address --- see
* MailAddressResolver.)
* <p>
* <p>
* Properties like {@link UserDetails#getPassword()} make no sense, so just return an empty value from it.
* The only information that you need to pay real attention is {@link UserDetails#getAuthorities()}, which
* is a list of roles/groups that the user is in. At minimum, this must contain {@link #AUTHENTICATED_AUTHORITY}
* (which indicates that this user is authenticated and not anonymous), but if your backend supports a notion
* of groups, you should make sure that the authorities contain one entry per one group. This enables
* users to control authorization based on groups.
* <p>
* <p>
* If the user name and the password pair doesn't match, throw {@link AuthenticationException} to reject the login
* attempt.
*
* @param username userName
*/
@Override
protected UserDetails authenticate(String username, String password)
throws AuthenticationException {
String token;
try {
token = getLoadingCache().get(new UserAuth(currentAuth.getTeamId(), username, password));
if (token == null || token.isEmpty()) {
logger.info(
String.format("Login failed. namespace: %s, username: %s", currentAuth.getTeamId(),
username));
throw new UsernameNotFoundException("Invalid login");
}
AppsCodeUserDetails userDetails = getUserDetails(currentAuth.getTeamId(), username, token);
if (!username.equals(userDetails.getUsername())) {
logger.warning(String.format("Username doesn't match. given: %s, found: %s", username,
userDetails.getUsername()));
throw new UsernameNotFoundException("Username doesn't match");
}
return userDetails;
} catch (UsernameNotFoundException ue) {
throw ue;
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("%s", e.getMessage()));
throw new UsernameNotFoundException(e.getMessage());
}
}
示例6: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
/**
* Retrieves information about an user by its name. <p> <p> This method is used, for example, to
* validate if the given token is a valid user name when the user is configuring an ACL. This is
* an optional method that improves the user experience. If your backend doesn't support a query
* like this, just always throw {@link UsernameNotFoundException}.
*/
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
return AppsCodeUserDetails
.fromUser(username);
}
示例7: userExists
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
private boolean userExists(HudsonSecurityRealmRegistration securityRealmRegistration, JSONObject object)
throws InvalidSecurityRealmException {
final String username = BaseFormField.USERNAME.fromJSON(object);
try {
securityRealmRegistration.getSecurityRealm().loadUserByUsername(username);
return true;
} catch (UsernameNotFoundException e) {
return false;
}
}
示例8: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
GitlabAPI api = GitlabAPI.connect(this.gitLabUrl, this.apiToken);
try {
GitlabUser[] users = api.retrieve().with("search", username).to(GitlabUser.URL, GitlabUser[].class);
if(ArrayUtils.isNotEmpty(users)) {
return this.userDetailsBuilder.buildUserDetails(this.gitLabUrl, users[0], null);
}
throw new UsernameNotFoundException("No user found: " + username);
} catch (IOException e) {
throw new UsernameNotFoundException("Couldn't find user: " + username, e);
}
}
示例9: loadGroupByGroupname
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public GroupDetails loadGroupByGroupname(final String groupName) throws UsernameNotFoundException, DataAccessException {
return new GroupDetails() {
@Override
public String getName() {
return groupName;
}
};
}
示例10: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username) {
UserDetails result = null;
DeepinAuthenticationToken authToken = (DeepinAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
if (authToken == null) {
throw new UsernameNotFoundException("DeepinAuthenticationToken = null, no known user: " + username);
}
result = new DeepinOAuthApiService(clientID, clientSecret).getUserByUsername(username);
if (result == null) {
throw new UsernameNotFoundException("User does not exist for login: " + username);
}
return result;
}
示例11: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
List users = usersByUsernameMapping.execute(username);
if (users.size() == 0) {
throw new UsernameNotFoundException("User not found");
}
UserDetails user = (UserDetails) users.get(0); // contains no GrantedAuthority[]
List dbAuths = authoritiesByUsernameMapping.execute(user.getUsername());
if (dbAuths.size() == 0) {
throw new UsernameNotFoundException("User has no GrantedAuthority");
}
GrantedAuthority[] arrayAuths = {};
addCustomAuthorities(user.getUsername(), dbAuths);
arrayAuths = (GrantedAuthority[]) dbAuths.toArray(arrayAuths);
String returnUsername = user.getUsername();
if (!isUsernameBasedPrimaryKey()) {
returnUsername = username;
}
return new User(returnUsername, user.getPassword(), user.isEnabled(),
true, true, true, arrayAuths);
}
示例12: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
/**
* Locates the user based on the username.
*
* @param username The username presented to the {@link DaoAuthenticationProvider}
* @return A fully populated user record (never <code>null</code>)
* @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority.
* @throws DataAccessException If user could not be found for a repository-specific reason.
*/
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
boolean unlocked = true;
User user = getUserByName(username);
if (user == null) {
throw new UsernameNotFoundException("User \"" + username + "\" was not found.");
}
// block disabled user at logon
if (username.equalsIgnoreCase("default") || user.isLocked()) {
unlocked = false;
}
String[] roles = userDao.getRolesForUser(username);
GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
for (int i = 0; i < roles.length; i++) {
authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase());
}
// If user is LDAP authenticated, disable user. The proper authentication should in that case
// be done by SubsonicLdapBindAuthenticator.
boolean enabled = !user.isLdapAuthenticated();
return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, unlocked, authorities);
}
示例13: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see hudson.security.AbstractPasswordBasedSecurityRealm#loadUserByUsername(java.lang.String)
*/
@Override
public UserDetails loadUserByUsername(String username) {
try {
RedmineManager redmineManager = getManager();
return getUserDetails(redmineManager.getUserByLogin(username));
} catch (RedmineException e) {
LOGGER.info("User {} not found", username);
throw new UsernameNotFoundException(e.getMessage(), e);
}
}
示例14: loadUserByUsername
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
initPython();
if (pexec.isImplemented(11)) {
return (UserDetails) pexec.execPython("load_user_by_username", username);
} else {
return super.loadUserByUsername(username);
}
}
示例15: loadGroupByGroupname
import org.acegisecurity.userdetails.UsernameNotFoundException; //导入依赖的package包/类
@Override
public GroupDetails loadGroupByGroupname(String groupname) throws UsernameNotFoundException, DataAccessException {
initPython();
if (pexec.isImplemented(12)) {
return (GroupDetails) pexec.execPython("load_group_by_groupname", groupname);
} else {
return super.loadGroupByGroupname(groupname);
}
}