use of org.springframework.security.core.userdetails.UsernameNotFoundException in project atlas by apache.
the class FileAuthenticationTest method testInValidUsernameLogin.
@Test
public void testInValidUsernameLogin() {
when(authentication.getName()).thenReturn("wrongUserName");
when(authentication.getCredentials()).thenReturn("wrongpassword");
try {
Authentication auth = authProvider.authenticate(authentication);
LOG.debug(" {}", auth);
} catch (UsernameNotFoundException uExp) {
assertTrue(uExp.getMessage().contains("Username not found."));
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project atlas by apache.
the class FileAuthenticationTest method testLoginWhenRolePasswordNotSet.
@Test
public void testLoginWhenRolePasswordNotSet() {
// for this user password details are set blank
when(authentication.getName()).thenReturn("user");
when(authentication.getCredentials()).thenReturn("P@ssword");
try {
Authentication auth = authProvider.authenticate(authentication);
LOG.debug(" {}", auth);
} catch (UsernameNotFoundException uExp) {
assertTrue(uExp.getMessage().startsWith("Username not found"));
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project atlas by apache.
the class UserDaoTest method testUserDaowithInValidLogin.
@Test
public void testUserDaowithInValidLogin() {
boolean hadException = false;
Properties userLogins = new Properties();
userLogins.put("admin", "ADMIN::admin123");
userLogins.put("test", "DATA_STEWARD::test123");
UserDao user = new UserDao();
user.setUserLogins(userLogins);
try {
User userBean = user.loadUserByUsername("xyz");
} catch (UsernameNotFoundException uex) {
hadException = true;
}
assertTrue(hadException);
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project danyuan-application by 514840279.
the class CustomUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
SysUserBaseInfo user;
try {
user = sysUserBaseService.findByName(userName);
} catch (Exception e) {
throw new UsernameNotFoundException("user select fail");
}
if (user == null) {
throw new UsernameNotFoundException("no user found");
} else {
try {
List<SysMenuInfo> menu = sysUserBaseService.getRoleByUser(user.getUuid());
List<GrantedAuthority> gas = new ArrayList<>();
if (menu != null) {
for (SysMenuInfo sysMenuInfo : menu) {
gas.add(new SimpleGrantedAuthority(sysMenuInfo.getName()));
}
}
// gas.add(new SwitchUserGrantedAuthority("ROLE_USER", new Authentication()));
UserDetails users = new User(user.getUserName(), user.getPassword(), true, true, true, true, gas);
return users;
} catch (Exception e) {
throw new UsernameNotFoundException("user role select fail");
}
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project atlas by apache.
the class UserDao method loadUserByUsername.
public User loadUserByUsername(final String username) throws AuthenticationException {
String userdetailsStr = userLogins.getProperty(username);
if (userdetailsStr == null || userdetailsStr.isEmpty()) {
throw new UsernameNotFoundException("Username not found." + username);
}
String password = "";
String role = "";
String[] dataArr = userdetailsStr.split("::");
if (dataArr != null && dataArr.length == 2) {
role = dataArr[0];
password = dataArr[1];
} else {
LOG.error("User role credentials is not set properly for {}", username);
throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
}
List<GrantedAuthority> grantedAuths = new ArrayList<>();
if (StringUtils.hasText(role)) {
grantedAuths.add(new SimpleGrantedAuthority(role));
} else {
LOG.error("User role credentials is not set properly for {}", username);
throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
}
User userDetails = new User(username, password, grantedAuths);
return userDetails;
}
Aggregations