Skip to content

Commit

Permalink
MID-9035: fix authentication for cluster nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 6, 2023
1 parent 9039c4a commit ea6ea60
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public String getSessionId() {
@Override
public boolean isAuthenticated() {
List<AuthenticationSequenceModuleType> modules = sequence.getModule();
if (modules.isEmpty()) {
return false;
if (modules.isEmpty() && !AuthUtil.isClusterAuthentication(MidpointAuthentication.this)) {
return false;
}

if (shouldEvaluateAuthentication()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,15 @@ private static boolean isPasswordResetAuthChannel(MidpointAuthentication authent
}
return SchemaConstants.CHANNEL_RESET_PASSWORD_URI.equals(authentication.getAuthenticationChannel().getChannelId());
}

public static boolean isClusterAuthentication(MidpointAuthentication authentication) {
if (authentication.getAuthModules().size() != 1) {
return false;
}
ModuleAuthentication baseAuthentication = authentication.getAuthModules().get(0).getBaseModuleAuthentication();
if (baseAuthentication == null) {
return false;
}
return AuthenticationModuleNameConstants.CLUSTER.equals(baseAuthentication.getModuleTypeName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public boolean authenticate(@Nullable String remoteName, String remoteAddress, @
LOGGER.trace("Established authenticity for remote {}", actualNode);
NodeAuthenticationTokenImpl authNtoken = new NodeAuthenticationTokenImpl(actualNode, remoteAddress,
Collections.emptyList());
authNtoken.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(authNtoken);
securityHelper.auditLoginSuccess(actualNode.asObjectable(), connEnv);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void sendStartAuthentication(HttpServletRequest request, HttpServletRe
requestCache.saveRequest(request, response);
}
if (reason != null) {
LOGGER.debug(reason.getMessage());
LOGGER.debug(reason.getMessage(), reason);
}
LOGGER.debug("Calling Authentication entry point.");
getAuthenticationEntryPoint().commence(request, response, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.authentication.api.config.MidpointAuthentication;
import com.evolveum.midpoint.authentication.api.util.AuthUtil;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -373,9 +375,21 @@ private boolean forbiddenFileName(String fileName) {

private void checkNodeAuthentication() throws SecurityViolationException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof NodeAuthenticationToken)) {
throw new SecurityViolationException("Node authentication is expected but not present");

if (!authentication.isAuthenticated()) {
throw new SecurityViolationException("Unauthenticated token");
}

if (authentication instanceof MidpointAuthentication) {
if (!AuthUtil.isClusterAuthentication((MidpointAuthentication) authentication)) {
throw new SecurityViolationException("Midpoint authentication for cluster is expected but not present");
}
} else {
if (!(authentication instanceof NodeAuthenticationToken)) {
throw new SecurityViolationException("Node authentication is expected but not present");
}
}

// TODO consider allowing administrator access here as well
}
}

0 comments on commit ea6ea60

Please sign in to comment.