use of org.simbasecurity.core.chain.Command.State.CONTINUE in project simba-os by cegeka.
the class CheckTokenCommand method execute.
@Override
public State execute(ChainContext context) throws Exception {
Optional<User> userFromToken = context.getToken().map(Token::fromString).flatMap(token -> userTokenService.getUserForToken(token));
Optional<User> userFromEmail = context.getEmail().map(s -> emailFactory.email(s)).flatMap(email -> credentialService.findUserByMail(email));
if (noExistingUserForEmail(context, userFromEmail))
return FINISH;
if (noExistingUserForToken(context, userFromEmail.get(), userFromToken))
return FINISH;
if (existingUsersDoNotMatch(context, userFromEmail.get(), userFromToken.get()))
return FINISH;
User user = userFromToken.get();
context.setUserName(user.getUserName());
AuditLogEvent event = auditLogEventFactory.createEventForUserAuthentication(user.getUserName(), String.format("There was a successful reset password attempt for email address %s.", user.getEmail().asString()));
audit.log(event);
return CONTINUE;
}
Aggregations