-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show error message to OAuth2 user when a matching local account already exists #116
Show error message to OAuth2 user when a matching local account already exists #116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly a Mono thing, the rest seems good to me :)
.map(auth -> { | ||
try { | ||
return Pair.of(resolver.resolve(auth), ""); | ||
} catch (DuplicatedEmailFoundException exp) { | ||
Optional<GeorchestraUser> op = Optional.empty(); | ||
return Pair.of(op, "/login?error=" + DUPLICATE_ACCOUNT); | ||
} | ||
})// | ||
.map(user -> { | ||
GeorchestraUser usr = user.orElse(null); | ||
if (!user.getRight().isEmpty()) { | ||
SecurityContextHolder.getContext(); | ||
ServerHttpResponse response = exchange.getResponse(); | ||
response.setStatusCode(HttpStatus.FOUND); | ||
response.getHeaders().setLocation(URI.create(user.getRight())); | ||
return exchange; | ||
} | ||
|
||
GeorchestraUser usr = user.getLeft().orElse(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to better understand Mono and ended up with something like (not fully working) :
.map(resolver::resolve)//
.map(user -> {
GeorchestraUser usr = user.orElse(null);
GeorchestraUsers.store(exchange, usr);
if (usr != null && usr instanceof ExtendedGeorchestraUser) {
ExtendedGeorchestraUser eu = (ExtendedGeorchestraUser) usr;
Organization org = eu.getOrg();
GeorchestraOrganizations.store(exchange, org);
}
return exchange;
})//
.doOnError(DuplicatedEmailFoundException.class, exp -> {
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.FOUND);
response.getHeaders().setLocation(URI.create("/login?error=" + DUPLICATE_ACCOUNT));
exchange.getSession().flatMap(WebSession::invalidate);
})
I think we can do something way better. I couldn't succeed to handle status code in error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we can do something this way, but still have to find the correct syntax. Your proposal run additional code if an exception is thrown but doesn't cancel the exception which is thrown anyway at the end of the Mono chain. In fact it's like a try-finally but we need instead something like a try-catch.
If a user tries to log with OAuth2 and a local account with the same e-mail address already exists, it should be presented a clear error messages about this conflict, and the user should not be considered logged in.
Follow up to PR#86 after a change of source branch.