Skip to content

Commit

Permalink
keycloak: Polishing example for Network based authentication step
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdarimont committed Nov 4, 2023
1 parent cbc4cee commit 0dcc22e
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,24 @@ public class NetworkAuthenticator implements Authenticator {
@Override
public void authenticate(AuthenticationFlowContext context) {

var remoteIp = resolveRemoteIp( //
context.getAuthenticatorConfig(), //
context.getHttpRequest(), //
context.getConnection().getRemoteAddr() //
);

var realm = context.getRealm();
var authSession = context.getAuthenticationSession();
var client = authSession.getClient();

var allowedNetworks = resolveAllowedNetworks(context.getAuthenticatorConfig(), client);
if (allowedNetworks == null) {
// skip check since we don't have any network restrictions configured
log.debugf("Skip check for source IP based on network. realm=%s, client=%s, IP=%s", //
realm.getName(), client.getClientId(), remoteIp);
log.debugf("Skip check for source IP based on network. realm=%s, client=%s", //
realm.getName(), client.getClientId());
context.success();
return;
}

var remoteIp = resolveRemoteIp( //
context.getAuthenticatorConfig(), //
context.getHttpRequest(), //
context.getConnection().getRemoteAddr() //
);
if (remoteIp == null) {
context.attempted();
log.warnf("Could not determine remoteIp, step marked as attempted. realm=%s, client=%s", //
Expand Down

0 comments on commit 0dcc22e

Please sign in to comment.