Skip to content

Instantly share code, notes, and snippets.

@aludwiko
Last active July 27, 2018 12:32
Show Gist options
  • Select an option

  • Save aludwiko/c1e5e0c2f590195176aeb216db6f7fd8 to your computer and use it in GitHub Desktop.

Select an option

Save aludwiko/c1e5e0c2f590195176aeb216db6f7fd8 to your computer and use it in GitHub Desktop.
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