Skip to content

Commit

Permalink
Generalize notifications a bit
Browse files Browse the repository at this point in the history
- password related functionality: UserType -> FocusType
- focal notifier: FocusType -> AssignmentHolderType

(cherry picked from commit ad0ce7c)
  • Loading branch information
mederly committed Mar 14, 2020
1 parent af42338 commit 671c141
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 44 deletions.
Expand Up @@ -991,15 +991,15 @@ Collection<String> getManagersOidsExceptUser(@NotNull Collection<ObjectReference

boolean isMemberOf(UserType user, String orgOid);

String getPlaintextUserPassword(UserType user) throws EncryptionException;
String getPlaintextUserPassword(FocusType user) throws EncryptionException;

String getPlaintext(ProtectedStringType user) throws EncryptionException;

String getPlaintextAccountPassword(ShadowType account) throws EncryptionException;

String getPlaintextAccountPasswordFromDelta(ObjectDelta<? extends ShadowType> delta) throws EncryptionException;

String getPlaintextUserPasswordFromDeltas(List<ObjectDelta<UserType>> deltas) throws EncryptionException;
String getPlaintextUserPasswordFromDeltas(List<ObjectDelta<? extends FocusType>> deltas) throws EncryptionException;

Task getCurrentTask();

Expand Down
Expand Up @@ -171,7 +171,7 @@ public boolean isMemberOf(UserType user, String orgOid) {
}

@Override
public String getPlaintextUserPassword(UserType user) throws EncryptionException {
public String getPlaintextUserPassword(FocusType user) throws EncryptionException {
if (user == null || user.getCredentials() == null || user.getCredentials().getPassword() == null) {
return null; // todo log a warning here?
}
Expand Down Expand Up @@ -256,15 +256,15 @@ private void takePasswordsFromItemDelta(List<ProtectedStringType> passwords, Ite
}

@Override
public String getPlaintextUserPasswordFromDeltas(List<ObjectDelta<UserType>> objectDeltas) throws EncryptionException {
public String getPlaintextUserPasswordFromDeltas(List<ObjectDelta<? extends FocusType>> objectDeltas) throws EncryptionException {

List<ProtectedStringType> passwords = new ArrayList<>();

for (ObjectDelta<UserType> delta : objectDeltas) {
for (ObjectDelta<? extends FocusType> delta : objectDeltas) {

if (delta.isAdd()) {
UserType newUser = delta.getObjectToAdd().asObjectable();
return getPlaintextUserPassword(newUser); // for simplicity we do not look for other values
FocusType newObject = delta.getObjectToAdd().asObjectable();
return getPlaintextUserPassword(newObject); // for simplicity we do not look for other values
}

if (!delta.isModify()) {
Expand Down
Expand Up @@ -834,7 +834,7 @@ public PrismObject<O> getObjectCurrentOrOld() {

@Override
public boolean isOfType(Class<?> aClass) {
if (objectTypeClass != null && aClass.isAssignableFrom(objectTypeClass)) {
if (aClass.isAssignableFrom(objectTypeClass)) {
return true;
}
PrismObject<O> object = getObjectAny();
Expand Down
Expand Up @@ -308,7 +308,7 @@ private boolean containsItemInValues(Collection<PrismValue> values, ItemPath rem
return false;
}

public boolean containsItem(List<ObjectDelta<FocusType>> deltas, ItemPath itemPath) {
boolean containsItem(List<ObjectDelta<AssignmentHolderType>> deltas, ItemPath itemPath) {
for (ObjectDelta objectDelta : deltas) {
if (containsItem(objectDelta, itemPath)) {
return true;
Expand Down
Expand Up @@ -22,11 +22,8 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventCategoryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang.StringUtils;

import javax.xml.namespace.QName;
Expand Down Expand Up @@ -149,23 +146,24 @@ public ObjectDelta<?> getFocusSecondaryDelta() {
return getFocusContext() != null ? getFocusContext().getSecondaryDelta() : null;
}

public List<ObjectDelta<FocusType>> getFocusDeltas() {
List<ObjectDelta<FocusType>> retval = new ArrayList<>();
public List<ObjectDelta<AssignmentHolderType>> getFocusDeltas() {
List<ObjectDelta<AssignmentHolderType>> retval = new ArrayList<>();
Class c = modelContext.getFocusClass();
if (c != null && FocusType.class.isAssignableFrom(c)) {
if (c != null && AssignmentHolderType.class.isAssignableFrom(c)) {
for (Object o : getFocusExecutedDeltas()) {
ObjectDeltaOperation objectDeltaOperation = (ObjectDeltaOperation) o;
//noinspection unchecked
retval.add(objectDeltaOperation.getObjectDelta());
}
}
return retval;
}

public ObjectDelta<? extends FocusType> getSummarizedFocusDeltas() throws SchemaException {
public ObjectDelta<? extends AssignmentHolderType> getSummarizedFocusDeltas() throws SchemaException {
return ObjectDeltaCollectionsUtil.summarize(getFocusDeltas());
}

public boolean hasFocusOfType(Class<? extends FocusType> clazz) {
public boolean hasFocusOfType(Class<? extends AssignmentHolderType> clazz) {
return getFocusContext() != null && clazz.isAssignableFrom(getFocusContext().getObjectTypeClass());
}

Expand Down
Expand Up @@ -294,7 +294,7 @@ public String getContentAsFormattedList(Event event, boolean showSynchronization
final ModelEvent modelEvent = (ModelEvent) event;
ModelContext<FocusType> modelContext = (ModelContext) modelEvent.getModelContext();
ModelElementContext<FocusType> focusContext = modelContext.getFocusContext();
ObjectDelta<? extends FocusType> summarizedDelta;
ObjectDelta<? extends ObjectType> summarizedDelta;
try {
summarizedDelta = modelEvent.getSummarizedFocusDeltas();
} catch (SchemaException e) {
Expand Down Expand Up @@ -369,7 +369,12 @@ public String getFocusPasswordFromEvent(ModelEvent modelEvent) {
LOGGER.trace("getFocusPasswordFromEvent: No user deltas in event");
return null;
}
String password = getPasswordFromDeltas(modelEvent.getFocusDeltas());
if (modelEvent.getFocusContext() == null || !modelEvent.getFocusContext().isOfType(FocusType.class)) {
LOGGER.trace("getFocusPasswordFromEvent: Not a FocusType context");
return null;
}
//noinspection unchecked,rawtypes
String password = getPasswordFromDeltas((List) modelEvent.getFocusDeltas());
if (password != null) {
LOGGER.trace("getFocusPasswordFromEvent: Found password in user executed delta(s)");
return password;
Expand Down Expand Up @@ -402,10 +407,9 @@ public String getFocusPasswordFromEvent(ModelEvent modelEvent) {
return null;
}

private String getPasswordFromDeltas(List<ObjectDelta<FocusType>> deltas) {
private String getPasswordFromDeltas(List<ObjectDelta<? extends FocusType>> deltas) {
try {
//noinspection unchecked
return midpointFunctions.getPlaintextUserPasswordFromDeltas((List) deltas);
return midpointFunctions.getPlaintextUserPasswordFromDeltas(deltas);
} catch (EncryptionException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't decrypt password from user deltas: {}", e, DebugUtil.debugDump(deltas));
return null;
Expand Down
Expand Up @@ -12,6 +12,8 @@
import java.util.Date;
import java.util.List;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Component;

Expand All @@ -27,16 +29,12 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimpleFocalObjectNotifierType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
*
* This is the "main" notifier that deals with modifications of focal objects i.e. AssignmentHolderType and below.
*/
@Component
public abstract class AbstractFocalObjectNotifier<C extends SimpleFocalObjectNotifierType, F extends FocusType> extends AbstractGeneralNotifier<ModelEvent, C> {
public abstract class AbstractFocalObjectNotifier<C extends SimpleFocalObjectNotifierType, F extends AssignmentHolderType> extends AbstractGeneralNotifier<ModelEvent, C> {

private static final Trace LOGGER = TraceManager.getTrace(AbstractFocalObjectNotifier.class);

Expand All @@ -60,14 +58,14 @@ protected boolean quickCheckApplicability(ModelEvent event, SimpleFocalObjectNot

@Override
protected boolean checkApplicability(ModelEvent event, C configuration, OperationResult result) {
List<ObjectDelta<FocusType>> deltas = event.getFocusDeltas();
List<ObjectDelta<AssignmentHolderType>> deltas = event.getFocusDeltas();
if (deltas.isEmpty()) {
LOGGER.trace("No deltas found, skipping the notification");
return false;
} else if (isWatchAuxiliaryAttributes(configuration)) {
return true;
} else {
for (ObjectDelta<FocusType> delta : deltas) {
for (ObjectDelta<AssignmentHolderType> delta : deltas) {
if (!delta.isModify() || deltaContainsOtherPathsThan(delta, functions.getAuxiliaryPaths())) {
return true;
}
Expand Down Expand Up @@ -103,15 +101,15 @@ protected String getBody(ModelEvent modelEvent, C configuration, String transpor
boolean techInfo = Boolean.TRUE.equals(configuration.isShowTechnicalInformation());

//noinspection unchecked
ModelContext<FocusType> modelContext = (ModelContext<FocusType>) modelEvent.getModelContext();
ModelElementContext<FocusType> focusContext = modelContext.getFocusContext();
PrismObject<FocusType> focusObject = focusContext.getObjectNew() != null ? focusContext.getObjectNew() : focusContext.getObjectOld();
FocusType focus = focusObject.asObjectable();
ModelContext<AssignmentHolderType> modelContext = (ModelContext<AssignmentHolderType>) modelEvent.getModelContext();
ModelElementContext<AssignmentHolderType> focusContext = modelContext.getFocusContext();
PrismObject<AssignmentHolderType> focusObject = focusContext.getObjectNew() != null ? focusContext.getObjectNew() : focusContext.getObjectOld();
AssignmentHolderType focus = focusObject.asObjectable();
String oid = focusContext.getOid();

String fullName = emptyIfNull(getFullName(focus));

ObjectDelta<FocusType> delta = ObjectDeltaCollectionsUtil.summarize(modelEvent.getFocusDeltas());
ObjectDelta<AssignmentHolderType> delta = ObjectDeltaCollectionsUtil.summarize(modelEvent.getFocusDeltas());

StringBuilder body = new StringBuilder();

Expand Down Expand Up @@ -150,14 +148,14 @@ protected String getBody(ModelEvent modelEvent, C configuration, String transpor
}

@Nullable
private String getFullName(FocusType focus) {
private String getFullName(AssignmentHolderType focus) {
String fullName;
if (focus instanceof UserType) {
fullName = PolyString.getOrig(((UserType) focus).getFullName());
} else if (focus instanceof AbstractRoleType) {
fullName = PolyString.getOrig(((AbstractRoleType) focus).getDisplayName());
} else {
fullName = ""; // TODO (currently it's not possible to get here)
fullName = ""; // TODO
}
return fullName;
}
Expand Down
Expand Up @@ -345,7 +345,7 @@ boolean deltaContainsOtherPathsThan(ObjectDelta<? extends ObjectType> delta, Lis
}

boolean isWatchAuxiliaryAttributes(N configuration) {
return Boolean.TRUE.equals((configuration).isWatchAuxiliaryAttributes());
return Boolean.TRUE.equals(configuration.isWatchAuxiliaryAttributes());
}

String formatRequester(E event, OperationResult result) {
Expand Down
Expand Up @@ -7,15 +7,16 @@

package com.evolveum.midpoint.notifications.impl.notifiers;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;

import org.springframework.stereotype.Component;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimpleFocalObjectNotifierType;

@Component
public class SimpleFocalObjectNotifier extends AbstractFocalObjectNotifier<SimpleFocalObjectNotifierType, FocusType> {
public class SimpleFocalObjectNotifier extends AbstractFocalObjectNotifier<SimpleFocalObjectNotifierType, AssignmentHolderType> {

private static final Trace LOGGER = TraceManager.getTrace(SimpleFocalObjectNotifier.class);

Expand All @@ -25,8 +26,8 @@ public Class<SimpleFocalObjectNotifierType> getEventHandlerConfigurationType() {
}

@Override
Class<FocusType> getFocusClass() {
return FocusType.class;
Class<AssignmentHolderType> getFocusClass() {
return AssignmentHolderType.class;
}

@Override
Expand Down

0 comments on commit 671c141

Please sign in to comment.