use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class PageRegistrationConfirmation method assignAdditionalRoleIfPresent.
private OperationResult assignAdditionalRoleIfPresent(String userOid, NonceType nonceType, OperationResult result) {
// SecurityContextHolder.getContext().setAuthentication(token);
return runPrivileged(() -> {
List<ItemDelta> userDeltas = new ArrayList<>();
if (nonceType.getName() != null) {
Task task = createAnonymousTask(OPERATION_FINISH_REGISTRATION);
ObjectDelta<UserType> assignRoleDelta = null;
try {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(ObjectTypeUtil.createObjectRef(nonceType.getName(), ObjectTypes.ABSTRACT_ROLE));
getPrismContext().adopt(assignment);
userDeltas.add((ItemDelta) ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
assignRoleDelta = ObjectDelta.createModifyDelta(userOid, userDeltas, UserType.class, getPrismContext());
assignRoleDelta.setPrismContext(getPrismContext());
} catch (SchemaException e) {
result.recordFatalError("Could not create delta");
return result;
}
WebModelServiceUtils.save(assignRoleDelta, result, task, PageRegistrationConfirmation.this);
result.computeStatusIfUnknown();
}
return result;
});
// SecurityContextHolder.getContext().setAuthentication(null);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class PageRegistrationConfirmation method assignDefaultRoles.
private OperationResult assignDefaultRoles(final String userOid) {
List<ContainerDelta<AssignmentType>> assignments = new ArrayList<>();
for (ObjectReferenceType defaultRole : getSelfRegistrationConfiguration().getDefaultRoles()) {
AssignmentType assignment = new AssignmentType();
assignment.setTargetRef(defaultRole);
try {
getPrismContext().adopt(assignment);
assignments.add(ContainerDelta.createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, getPrismContext(), assignment));
} catch (SchemaException e) {
//nothing to do
}
}
final ObjectDelta<UserType> delta = ObjectDelta.createModifyDelta(userOid, assignments, UserType.class, getPrismContext());
return runPrivileged(new Producer<OperationResult>() {
@Override
public OperationResult run() {
OperationResult result = new OperationResult(OPERATION_ASSIGN_DEFAULT_ROLES);
Task task = createAnonymousTask(OPERATION_ASSIGN_DEFAULT_ROLES);
WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
result.computeStatusIfUnknown();
return result;
}
});
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class MidPointAsserts method assertAssignments.
public static <F extends FocusType> void assertAssignments(PrismObject<F> user, Class expectedType, int expectedNumber) {
F userType = user.asObjectable();
int actualAssignments = 0;
List<AssignmentType> assignments = userType.getAssignment();
for (AssignmentType assignment : assignments) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef != null) {
QName type = targetRef.getType();
if (type != null) {
Class<? extends ObjectType> assignmentTargetClass = ObjectTypes.getObjectTypeFromTypeQName(type).getClassDefinition();
if (expectedType.isAssignableFrom(assignmentTargetClass)) {
actualAssignments++;
}
}
}
}
assertEquals("Unexepected number of assignments of type " + expectedType + " in " + user + ": " + userType.getAssignment(), expectedNumber, actualAssignments);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class MidPointAsserts method assertAssignedResource.
public static <F extends FocusType> void assertAssignedResource(PrismObject<F> user, String resourceOid) {
F userType = user.asObjectable();
for (AssignmentType assignmentType : userType.getAssignment()) {
if (assignmentType.getConstruction() == null) {
continue;
}
ObjectReferenceType targetRef = assignmentType.getConstruction().getResourceRef();
if (targetRef != null) {
if (resourceOid.equals(targetRef.getOid())) {
return;
}
}
}
AssertJUnit.fail(user + " does NOT have assigned resource " + resourceOid + " while expecting it");
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class MidPointAsserts method assertAssigned.
public static <F extends FocusType> AssignmentType assertAssigned(PrismObject<F> user, String targetOid, QName refType) {
F userType = user.asObjectable();
for (AssignmentType assignmentType : userType.getAssignment()) {
ObjectReferenceType targetRef = assignmentType.getTargetRef();
if (targetRef != null) {
if (refType.equals(targetRef.getType())) {
if (targetOid.equals(targetRef.getOid())) {
return assignmentType;
}
}
}
}
AssertJUnit.fail(user + " does not have assigned " + refType.getLocalPart() + " " + targetOid);
// not reachable
return null;
}
Aggregations