Search in sources :

Example 1 with FINISH

use of org.simbasecurity.core.chain.Command.State.FINISH 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;
}
Also used : AuditLogEventFactory(org.simbasecurity.core.audit.AuditLogEventFactory) CONTINUE(org.simbasecurity.core.chain.Command.State.CONTINUE) FINISH(org.simbasecurity.core.chain.Command.State.FINISH) Autowired(org.springframework.beans.factory.annotation.Autowired) ChainContext(org.simbasecurity.core.chain.ChainContext) UserTokenService(org.simbasecurity.core.service.communication.token.UserTokenService) EmailFactory(org.simbasecurity.core.domain.user.EmailFactory) User(org.simbasecurity.core.domain.User) Component(org.springframework.stereotype.Component) Command(org.simbasecurity.core.chain.Command) CredentialService(org.simbasecurity.core.service.CredentialService) Audit(org.simbasecurity.core.audit.Audit) AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Optional(java.util.Optional) Token(org.simbasecurity.core.domain.communication.token.Token) AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) User(org.simbasecurity.core.domain.User)

Aggregations

Optional (java.util.Optional)1 Audit (org.simbasecurity.core.audit.Audit)1 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)1 AuditLogEventFactory (org.simbasecurity.core.audit.AuditLogEventFactory)1 ChainContext (org.simbasecurity.core.chain.ChainContext)1 Command (org.simbasecurity.core.chain.Command)1 CONTINUE (org.simbasecurity.core.chain.Command.State.CONTINUE)1 FINISH (org.simbasecurity.core.chain.Command.State.FINISH)1 User (org.simbasecurity.core.domain.User)1 Token (org.simbasecurity.core.domain.communication.token.Token)1 EmailFactory (org.simbasecurity.core.domain.user.EmailFactory)1 CredentialService (org.simbasecurity.core.service.CredentialService)1 UserTokenService (org.simbasecurity.core.service.communication.token.UserTokenService)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1