private <T extends ObjectType> PrismObject<T> throwObjectNotFoundException(Class<T> type, String oid) throws ObjectNotFoundException { throw new ObjectNotFoundException("Object of type '" + type.getSimpleName() + "' with oid '" + oid + "' was not found.", null, oid); }
@Override public MidPointUserProfilePrincipal getPrincipal(String username) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { OperationResult result = new OperationResult(OPERATION_GET_PRINCIPAL); PrismObject<UserType> user; try { user = findByUsername(username, result); if (user == null) { throw new ObjectNotFoundException("Couldn't find user with name '" + username + "'"); } } catch (ObjectNotFoundException ex) { LOGGER.trace("Couldn't find user with name '{}', reason: {}.", username, ex.getMessage(), ex); throw ex; } catch (Exception ex) { LOGGER.warn("Error getting user with name '{}', reason: {}.", username, ex.getMessage(), ex); throw new SystemException(ex.getMessage(), ex); } return getPrincipal(user, null, result); }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try { return getPrincipal(username); } catch (ObjectNotFoundException e) { throw new UsernameNotFoundException(e.getMessage(), e); } catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) { throw new SystemException(e.getMessage(), e); } }
@Test public void test200AddUnresolvable() throws Exception { final String TEST_NAME = "test200AddUnresolvable"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestPolicyRules2.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); LensContext<RoleType> context = createLensContext(RoleType.class); fillContextWithAddDelta(context, prismContext.parseObject(ROLE_UNRESOLVABLE_REFERENCES_FILE)); display("Input context", context); assertFocusModificationSanity(context); // WHEN TestUtil.displayWhen(TEST_NAME); try { clockwork.run(context, task, result); TestUtil.displayThen(TEST_NAME); fail("unexpected success"); } catch (ObjectNotFoundException e) { TestUtil.displayThen(TEST_NAME); System.out.println("Expected exception: " + e); e.printStackTrace(System.out); if (!e.getMessage().contains("No policy constraint named 'unresolvable' could be found")) { fail("Exception message was not as expected: " + e.getMessage()); } } }
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, opResult).asObjectable(); } catch (ObjectNotFoundException ex) { LOGGER.error("Live Sync: Resource {} not found: {}", resourceOid, ex.getMessage(), ex); LOGGER.error("Live Sync: A required object does not exist, OID: {}", ex.getOid()); LOGGER.error("Exception stack trace", ex); opResult.recordFatalError("A required object does not exist, OID: " + ex.getOid(), ex); runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR); return runResult;
protected <T extends ObjectType> void assertObjectExists(Class<T> clazz, String oid) { OperationResult result = new OperationResult("assertObjectExists"); try { repositoryService.getObject(clazz, oid, null, result); } catch (ObjectNotFoundException e) { fail("Object of type " + clazz.getName() + " with OID " + oid + " doesn't exist: " + e.getMessage()); } catch (SchemaException e) { throw new SystemException("Object of type " + clazz.getName() + " with OID " + oid + " probably exists but couldn't be read: " + e.getMessage(), e); } }
private static void processActionToInclude( String actionToInclude, Map<String, Pair<ApprovalPolicyActionType, EvaluatedPolicyRule>> actionsMap, Map.Entry<WfProcessSpecificationType, List<Pair<ApprovalPolicyActionType, EvaluatedPolicyRule>>> processSpecificationEntry, boolean mustBePresent) throws ObjectNotFoundException { Pair<ApprovalPolicyActionType, EvaluatedPolicyRule> actionWithRule = actionsMap.get(actionToInclude); if (actionWithRule != null) { processSpecificationEntry.getValue().add(actionWithRule); } else if (mustBePresent) { throw new ObjectNotFoundException("Approval action '" + actionToInclude + "' cannot be found"); } }
} catch (ObjectNotFoundException e) { throw new ObjectNotFoundException("Couldn't evaluate tolerant/intolerant values for association " + isCValue + ", because the association target object does not exist: " + e.getMessage(), e);
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { // TODO Auto-generated method stub try { return getPrincipal(username); } catch (ObjectNotFoundException e) { throw new UsernameNotFoundException(e.getMessage(), e); } catch (SchemaException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
@Override protected void throwException(Exception cause, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, OperationResult result) throws ObjectNotFoundException { recordCompletionError(cause, opState, result); if (cause instanceof ObjectNotFoundException) { throw (ObjectNotFoundException)cause; } else { throw new ObjectNotFoundException(cause.getMessage(), cause); } }
private ConnectorInstance createConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException { ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result); ConnectorFactory connectorFactory = determineConnectorFactory(connectorType); ConnectorInstance connector = null; try { InternalMonitor.recordCount(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT); connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.getResource().getName().toString(), connectorSpec.toString()); } catch (ObjectNotFoundException e) { result.recordFatalError(e.getMessage(), e); throw new ObjectNotFoundException(e.getMessage(), e); } // This log message should be INFO level. It happens only occasionally. // If it happens often, it may be an // indication of a problem. Therefore it is good for admin to see it. LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion()); return connector; }
@NotNull private <O extends ObjectType> List<PrismObject<O>> getTargets(AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException { AssignmentType assignmentType = getAssignmentType(segment, ctx); if (assignmentType.getTarget() != null) { return Collections.singletonList((PrismObject<O>) assignmentType.getTarget().asPrismObject()); } else if (assignmentType.getTargetRef() != null) { try { return resolveTargets(segment, ctx); } catch (ObjectNotFoundException ex) { // Do not throw an exception. We don't have referential integrity. Therefore if a role is deleted then throwing // an exception would prohibit any operations with the users that have the role, including removal of the reference. // The failure is recorded in the result and we will log it. It should be enough. LOGGER.error(ex.getMessage()+" in assignment target reference in "+segment.sourceDescription,ex); // For OrgType references we trigger the reconciliation (see MID-2242) ctx.evalAssignment.setForceRecon(true); return Collections.emptyList(); } } else { throw new IllegalStateException("Both target and targetRef are null. We should not be here. Assignment: " + assignmentType); } }
private ConnectorStruct getConnectorStruct(ConnectorType connectorType) throws ObjectNotFoundException { if (connectorMap == null) { discoverConnectors(); } String type = connectorType.getConnectorType(); ConnectorStruct struct = connectorMap.get(type); if (struct == null) { throw new ObjectNotFoundException("No built-in connector type "+type); } return struct; }
private void preprocessEntitlement(ProvisioningContext ctx, PrismContainerValue<ShadowAssociationType> association, String desc, OperationResult result) throws SchemaException, ObjectNotFoundException, ConfigurationException, CommunicationException, ExpressionEvaluationException { PrismContainer<Containerable> identifiersContainer = association .findContainer(ShadowAssociationType.F_IDENTIFIERS); if (identifiersContainer != null && !identifiersContainer.isEmpty()) { // We already have identifiers here return; } ShadowAssociationType associationType = association.asContainerable(); if (associationType.getShadowRef() == null || StringUtils.isEmpty(associationType.getShadowRef().getOid())) { throw new SchemaException( "No identifiers and no OID specified in entitlements association " + association); } PrismObject<ShadowType> repoShadow; try { repoShadow = repositoryService.getObject(ShadowType.class, associationType.getShadowRef().getOid(), null, result); } catch (ObjectNotFoundException e) { throw new ObjectNotFoundException(e.getMessage() + " while resolving entitlement association OID in " + association + " in " + desc, e); } shadowCaretaker.applyAttributesDefinition(ctx, repoShadow); transplantIdentifiers(association, repoShadow); }
@Override public Collection<OrgType> getParentOrgs(ObjectType object, QName relation, String orgType, boolean preAuthorized) throws SchemaException, SecurityViolationException { List<ObjectReferenceType> parentOrgRefs = object.getParentOrgRef(); List<OrgType> parentOrgs = new ArrayList<>(parentOrgRefs.size()); for (ObjectReferenceType parentOrgRef: parentOrgRefs) { if (!prismContext.relationMatches(relation, parentOrgRef.getRelation())) { continue; } OrgType parentOrg; try { parentOrg = getObject(OrgType.class, parentOrgRef.getOid(), preAuthorized); } catch (ObjectNotFoundException e) { LOGGER.warn("Org "+parentOrgRef.getOid()+" specified in parentOrgRef in "+object+" was not found: "+e.getMessage(), e); // but do not rethrow, just skip this continue; } catch (CommunicationException | ConfigurationException | ExpressionEvaluationException e) { // This should not happen. throw new SystemException(e.getMessage(), e); } if (orgType == null || determineSubTypes(parentOrg).contains(orgType)) { parentOrgs.add(parentOrg); } } return parentOrgs; }
private String resolveLdapName(DirContextOperations ctx, String username) throws NamingException, ObjectNotFoundException { Attribute ldapResponse = ctx.getAttributes().get(ldapNamingAttr); if (ldapResponse != null) { if (ldapResponse.size() == 1) { Object namingAttrValue = ldapResponse.get(0); if (namingAttrValue != null) { return namingAttrValue.toString().toLowerCase(); } } else { throw new ObjectNotFoundException("Bad response"); // naming attribute contains multiple values } } return username; // fallback to typed-in username in case ldap value is missing } }
throw new ObjectNotFoundException("Object not found during variable " + varDesc + " resolution in " + contextDescription + ": " + e.getMessage(), e, ref.getOid()); } catch (SchemaException e) { throw new SchemaException("Schema error during variable " + varDesc + " resolution in "
@NotNull private Map<String, GroupExecInfo> createGroupMap(TaskQuartzImpl task, OperationResult result) { Map<String, GroupExecInfo> groupMap = new HashMap<>(); Map<String, Integer> groupsWithLimits = task.getGroupsWithLimits(); if (!groupsWithLimits.isEmpty()) { groupsWithLimits.forEach((g, l) -> groupMap.put(g, new GroupExecInfo(l))); ClusterStatusInformation csi = taskManagerImpl.getExecutionManager() .getClusterStatusInformation(true, false, result); for (ClusterStatusInformation.TaskInfo taskInfo : csi.getTasks()) { if (task.getOid().equals(taskInfo.getOid())) { continue; } Task otherTask; try { otherTask = taskManagerImpl.getTask(taskInfo.getOid(), result); } catch (ObjectNotFoundException e) { LOGGER.debug("Couldn't find running task {} when checking execution constraints: {}", taskInfo.getOid(), e.getMessage()); continue; } catch (SchemaException e) { LoggingUtils.logUnexpectedException(LOGGER, "Couldn't retrieve running task {} when checking execution constraints", e, taskInfo.getOid()); continue; } addToGroupMap(groupMap, otherTask); } } return groupMap; }
@Override public PrismSchema generateConnectorConfigurationSchema(ConnectorType connectorType) throws ObjectNotFoundException { ConnectorInfo cinfo = getConnectorInfo(connectorType); if (cinfo == null) { throw new ObjectNotFoundException("Connector "+connectorType+" cannot be found by ConnId framework"); } return generateConnectorConfigurationSchema(cinfo, connectorType); }
} catch (ObjectNotFoundException e) { parentResult.recordFatalError( "Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e); throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass="+ PrettyPrinter.prettyPrint(objectClassDefinition.getTypeName())+": " + e.getMessage(), e); } catch (CommunicationException e) { parentResult.recordFatalError("Error communication with the connector " + connector