use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class WebModelServiceUtils method getLoggedInUserOid.
public static String getLoggedInUserOid() {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
Validate.notNull(principal, "No principal");
if (principal.getOid() == null) {
throw new IllegalArgumentException("No OID in principal: " + principal);
}
return principal.getOid();
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class PageBase method setTimeZone.
protected void setTimeZone(PageBase page) {
PrismObject<UserType> user = loadUserSelf(page);
String timeZone = null;
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
if (user != null && user.asObjectable().getTimezone() != null) {
timeZone = user.asObjectable().getTimezone();
} else {
timeZone = principal.getAdminGuiConfiguration().getDefaultTimezone();
}
if (timeZone != null) {
WebSession.get().getClientInfo().getProperties().setTimeZone(TimeZone.getTimeZone(timeZone));
}
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class PageProcessInstances method stopProcessInstancesPerformed.
private void stopProcessInstancesPerformed(AjaxRequestTarget target) {
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
List<ProcessInstanceDto> selectedStoppableInstances = new ArrayList<>();
for (Selectable row : WebComponentUtil.getSelectedData(getTable())) {
ProcessInstanceDto instance = (ProcessInstanceDto) row;
if (instance.getEndTimestamp() == null) {
selectedStoppableInstances.add(instance);
}
}
if (!isSomeItemSelected(selectedStoppableInstances, true, target)) {
return;
}
OperationResult result = new OperationResult(OPERATION_STOP_PROCESS_INSTANCES);
WorkflowService workflowService = getWorkflowService();
for (ProcessInstanceDto instance : selectedStoppableInstances) {
try {
workflowService.stopProcessInstance(instance.getProcessInstanceId(), WebComponentUtil.getOrigStringFromPoly(user.getName()), result);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | RuntimeException ex) {
result.createSubresult(OPERATION_STOP_PROCESS_INSTANCE).recordPartialError("Couldn't stop process instance " + instance.getName(), ex);
}
}
if (result.isUnknown()) {
result.recomputeStatus();
}
if (result.isSuccess()) {
result.recordStatus(OperationResultStatus.SUCCESS, "Selected process instance(s) have been successfully stopped.");
}
showResult(result);
ProcessInstanceDtoProvider provider = (ProcessInstanceDtoProvider) getTable().getDataTable().getDataProvider();
provider.clearCache();
//refresh feedback and table
target.add(getFeedbackPanel());
target.add(getTable());
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class RunReportPopupPanel method createSimpleTask.
public Task createSimpleTask(String operation, PrismObject<UserType> owner) {
Task task = getPageBase().getTaskManager().createTaskInstance(operation);
if (owner == null) {
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
if (user == null) {
return task;
} else {
owner = user.getUser().asPrismObject();
}
}
task.setOwner(owner);
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
return task;
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class ExpressionUtil method addActorVariable.
public static void addActorVariable(ExpressionVariables scriptVariables, SecurityEnforcer securityEnforcer) {
// There can already be a value, because for mappings, we create the
// variable before parsing sources.
// For other scripts we do it just before the execution, to catch all
// possible places where scripts can be executed.
UserType oldActor = (UserType) scriptVariables.get(ExpressionConstants.VAR_ACTOR);
if (oldActor != null) {
return;
}
UserType actor = null;
try {
if (securityEnforcer != null) {
if (!securityEnforcer.isAuthenticated()) {
// This is most likely evaluation of role
// condition before
// the authentication is complete.
scriptVariables.addVariableDefinition(ExpressionConstants.VAR_ACTOR, null);
return;
}
MidPointPrincipal principal = securityEnforcer.getPrincipal();
if (principal != null) {
actor = principal.getUser();
}
}
if (actor == null) {
LOGGER.debug("Couldn't get principal information - the 'actor' variable is set to null");
}
} catch (SecurityViolationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get principal information - the 'actor' variable is set to null", e);
}
scriptVariables.addVariableDefinition(ExpressionConstants.VAR_ACTOR, actor);
}
Aggregations