Skip to content

Commit

Permalink
fix for refreshing of principal compiled gui when was changed assignm…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
skublik committed Oct 2, 2023
1 parent 5966ebf commit b6334f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public ObjectDetailsModels(LoadableDetachableModel<PrismObject<O>> prismObjectMo
protected PrismObjectWrapper<O> load() {
PrismObject<O> prismObject = getPrismObject();//prismObjectModel.getObject();

if (prismObject == null) {
return null;
}

PrismObjectWrapperFactory<O> factory = modelServiceLocator.findObjectWrapperFactory(prismObject.getDefinition());
Task task = modelServiceLocator.createSimpleTask("createWrapper");
OperationResult result = task.getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.evolveum.midpoint.authentication.api.AuthenticationChannel;
import com.evolveum.midpoint.authentication.api.config.MidpointAuthentication;
import com.evolveum.midpoint.authentication.impl.FocusAuthenticationResultRecorder;
import com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal;
import com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipalManager;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.ConnectionEnvironment;
Expand All @@ -28,6 +29,7 @@
import org.jetbrains.annotations.VisibleForTesting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;
Expand All @@ -53,6 +55,9 @@ public void setPrincipalManager(GuiProfiledPrincipalManager focusProfileService)
this.focusProfileService = focusProfileService;
}

@Autowired(required = false)
private SessionRegistry sessionRegistry;

public FinishAuthenticationFilter() {
}

Expand Down Expand Up @@ -85,8 +90,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
return;
}

if (!(mpAuthentication.getPrincipal() instanceof MidPointPrincipal)) {
LOGGER.trace("Skipping compile principal profile, because couldn't find MidPointPrincipal.");
if (!(mpAuthentication.getPrincipal() instanceof GuiProfiledPrincipal)) {
LOGGER.trace("Skipping compile principal profile, because couldn't find GuiProfiledPrincipal.");
filterChain.doFilter(request, response);
return;
}
Expand All @@ -105,19 +110,13 @@ private void compileGuiProfile(MidpointAuthentication mpAuthentication) {
return;
}

try {
mpAuthentication.setPrincipal(
focusProfileService.getPrincipal(
principal.getFocusPrismObject(),
ProfileCompilerOptions.create()
.collectAuthorization(true)
.compileGuiAdminConfiguration(supportGuiConfig)
.locateSecurityPolicy(supportGuiConfig)
.tryReusingSecurityPolicy(true),
new OperationResult("reload principal")));
mpAuthentication.setAlreadyCompiledGui(true);
} catch (CommonException e) {
LOGGER.debug("Couldn't reload principal after authentication", e);
}
focusProfileService.refreshCompiledProfile(
(GuiProfiledPrincipal) principal,
ProfileCompilerOptions.create()
.collectAuthorization(true)
.compileGuiAdminConfiguration(supportGuiConfig)
.locateSecurityPolicy(supportGuiConfig)
.tryReusingSecurityPolicy(true));
mpAuthentication.setAlreadyCompiledGui(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ GuiProfiledPrincipal getPrincipal(

@NotNull
CompiledGuiProfile refreshCompiledProfile(GuiProfiledPrincipal guiProfiledPrincipal);

@NotNull
CompiledGuiProfile refreshCompiledProfile(GuiProfiledPrincipal guiProfiledPrincipal, ProfileCompilerOptions options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean

@Override
public @NotNull CompiledGuiProfile refreshCompiledProfile(GuiProfiledPrincipal principal) {
return refreshCompiledProfile(
principal,
ProfileCompilerOptions.create()
.compileGuiAdminConfiguration(true)
.collectAuthorization(true)
.locateSecurityPolicy(true));
}

@Override
public @NotNull CompiledGuiProfile refreshCompiledProfile(GuiProfiledPrincipal principal, ProfileCompilerOptions options) {
OperationResult result = new OperationResult("refreshCompiledProfile");

// Maybe focus was also changed, we should probably reload it
Expand All @@ -483,7 +493,7 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean
} catch (ObjectNotFoundException e) {
throw new SystemException("Focus was deleted");
} catch (SchemaException e) {
throw new SystemException("Encountered schema exception", e);
throw new SystemException("Encountered schema exception", e);
}
securityContextManager.setTemporaryPrincipalOid(focusOid);
try {
Expand All @@ -496,10 +506,7 @@ public <O extends ObjectType> void invalidate(Class<O> type, String oid, boolean
principal,
systemConfiguration,
null,
ProfileCompilerOptions.create()
.compileGuiAdminConfiguration(true)
.collectAuthorization(true)
.locateSecurityPolicy(true));
options);
principal.clearEffectivePrivilegesModification(); // we just recomputed them strictly from user's assignments
return principal.getCompiledGuiProfile();
} finally {
Expand Down

0 comments on commit b6334f9

Please sign in to comment.