use of org.springframework.security.core.userdetails.UsernameNotFoundException in project spring-thymeleaf-simplefinance by heitkergm.
the class UserDetailsDaoImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(final String userName) throws UsernameNotFoundException {
List<LoginUser> users = userRepository.findByUserName(userName);
if (users.size() <= 0) {
throw new UsernameNotFoundException("User Name " + userName + " not found.");
}
LoginUser luser = users.get(0);
UserDetails user = new User(luser.getUserName(), luser.getPassword(), YesNoEnum.toBoolean(luser.getEnabled()), true, true, true, AuthorityUtils.NO_AUTHORITIES);
return user;
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project Gemma by PavlidisLab.
the class AclCollectionBeforeTest method setup.
@Before
public final void setup() {
one = super.getTestPersistentBasicExpressionExperiment();
two = super.getTestPersistentBasicExpressionExperiment();
securityService.makePublic(one);
securityService.makePublic(two);
ees = new HashSet<>();
ees.add(one);
ees.add(two);
try {
userManager.loadUserByUsername(userName);
} catch (UsernameNotFoundException e) {
userManager.createUser(new UserDetailsImpl("foo", userName, true, null, RandomStringUtils.randomAlphabetic(10) + "@gmail.com", "key", new Date()));
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project Gemma by PavlidisLab.
the class ManualAuthenticationProcessingTest method before.
@Before
public void before() {
pwd = this.randomName();
username = this.randomName();
try {
userManager.loadUserByUsername(username);
} catch (UsernameNotFoundException e) {
String encodedPassword = passwordEncoder.encodePassword(pwd, username);
UserDetailsImpl u = new UserDetailsImpl(encodedPassword, username, true, null, null, null, new Date());
userManager.createUser(u);
}
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project Gemma by PavlidisLab.
the class ExecutingTaskTest method testSecurityContextManagement.
@Test
public void testSecurityContextManagement() {
try {
this.userManager.loadUserByUsername("ExecutingTaskTestUser");
} catch (UsernameNotFoundException e) {
this.userManager.createUser(new UserDetailsImpl("foo", "ExecutingTaskTestUser", true, null, "fooUser@chibi.ubc.ca", "key", new Date()));
}
this.runAsUser("ExecutingTaskTestUser");
TaskCommand taskCommand = new TaskCommand();
this.runAsAdmin();
Task<TaskResult, TaskCommand> task = new SuccessTestTask();
task.setTaskCommand(taskCommand);
ExecutingTask<TaskResult> executingTask = new ExecutingTask<>(task, taskCommand);
executingTask.setProgressAppender(progressAppender);
executingTask.setStatusCallback(statusSecurityContextCheckerHandler);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<TaskResult> future = executorService.submit(executingTask);
this.tryGetAnswer(future);
assertEquals(taskCommand.getSecurityContext(), securityContextAfterInitialize);
assertNotSame(taskCommand.getSecurityContext(), securityContextAfterFinish);
assertEquals(null, securityContextAfterFail);
}
use of org.springframework.security.core.userdetails.UsernameNotFoundException in project Gemma by PavlidisLab.
the class UserManagerImpl method changePasswordForUser.
@Override
@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "RUN_AS_ADMIN" })
@Transactional
public String changePasswordForUser(String email, String username, String newPassword) throws AuthenticationException {
Authentication currentAuthentication = SecurityContextHolder.getContext().getAuthentication();
if (currentAuthentication == null) {
// This would indicate bad coding somewhere
throw new AccessDeniedException("Can't change password as no Authentication object found in context " + "for current user.");
}
User u = userService.findByEmail(email);
if (u == null) {
throw new UsernameNotFoundException("No user found for that email address.");
}
String foundUsername = u.getUserName();
if (!foundUsername.equals(username)) {
throw new AccessDeniedException("Wrong user name was provided for the email address.");
}
logger.debug("Changing password for user '" + username + "'");
u.setPassword(newPassword);
u.setEnabled(false);
u.setSignupToken(this.generateSignupToken(username));
u.setSignupTokenDatestamp(new Date());
userService.update(u);
userCache.removeUserFromCache(username);
return u.getSignupToken();
}
Aggregations