Skip to content

Commit

Permalink
fix for redirect authenticated users from login pages
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Dec 20, 2022
1 parent 5200112 commit dfd34ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.evolveum.midpoint.authentication.api.authorization.PageDescriptor;
import com.evolveum.midpoint.authentication.api.config.ModuleAuthentication;
import com.evolveum.midpoint.gui.api.page.PageAdminLTE;

import com.evolveum.midpoint.web.component.menu.top.LocaleTextPanel;
Expand Down Expand Up @@ -152,16 +154,29 @@ private void showExceptionMessage() {
@Override
protected void onBeforeRender() {
super.onBeforeRender();
confirmUserPrincipal();
confirmAuthentication();
}

@Override
protected void onAfterRender() {
super.onAfterRender();
}

protected void confirmUserPrincipal() {
if (AuthUtil.getPrincipalUser() != null) {
protected void confirmAuthentication() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

boolean loginPageForAnotherModule = false;
if (authentication instanceof MidpointAuthentication) {
PageDescriptor descriptor = getClass().getAnnotation(PageDescriptor.class);
if (descriptor != null && !descriptor.authModule().isEmpty()) {
ModuleAuthentication module = ((MidpointAuthentication) authentication).getProcessingModuleAuthentication();
if (module != null) {
loginPageForAnotherModule = !module.getModuleTypeName().equals(descriptor.authModule());
}
}
}

if (authentication.isAuthenticated() || loginPageForAnotherModule) {
MidPointApplication app = getMidpointApplication();
throw new RestartResponseException(app.getHomePage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ private List<IdentityProvider> getProviders() {
protected abstract String getErrorKeyEmptyProviders();

@Override
protected void confirmUserPrincipal() {
protected void confirmAuthentication() {
}
}

0 comments on commit dfd34ab

Please sign in to comment.