Last active
July 27, 2018 12:32
-
-
Save aludwiko/c1e5e0c2f590195176aeb216db6f7fd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.axonframework.commandhandling.CommandHandler; | |
| import org.axonframework.commandhandling.model.AggregateIdentifier; | |
| import org.axonframework.eventsourcing.EventSourcingHandler; | |
| import org.axonframework.samples.trader.api.users.*; | |
| import org.axonframework.samples.trader.users.util.DigestUtils; | |
| import org.axonframework.spring.stereotype.Aggregate; | |
| import static org.axonframework.commandhandling.model.AggregateLifecycle.apply; | |
| @Aggregate(repository = "userAggregateRepository") | |
| public class User { | |
| @AggregateIdentifier | |
| private UserId userId; | |
| private String passwordHash; | |
| public User() { | |
| // Required by Axon Framework | |
| } | |
| ... | |
| @CommandHandler | |
| public boolean handle(AuthenticateUserCommand cmd) { | |
| boolean success = this.passwordHash.equals(hashOf(cmd.getPassword())); | |
| if (success) { | |
| apply(new UserAuthenticatedEvent(userId)); | |
| } | |
| return success; | |
| } | |
| @EventSourcingHandler | |
| public void on(UserCreatedEvent event) { | |
| this.userId = event.getUserId(); | |
| this.passwordHash = event.getPassword(); | |
| } | |
| private String hashOf(char[] password) { | |
| return DigestUtils.sha1(String.valueOf(password)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment