@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); } }
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); } }
@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); } }
@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); } }
@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 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; }
@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; }
+ ", because the association target object does not exist: " + e.getMessage(), e);
private <T extends ObjectType> PrismObject<T> getRepoObject(Class<T> type, String oid, GetOperationOptions options, OperationResult result) throws ObjectNotFoundException, SchemaException{ try { return getCacheRepositoryService().getObject(type, oid, null, result); } catch (ObjectNotFoundException e) { if (!GetOperationOptions.isAllowNotFound(options)){ ProvisioningUtil.recordFatalError(LOGGER, result, "Can't get object with oid " + oid + ". Reason " + e.getMessage(), e); } else { result.muteLastSubresultError(); result.computeStatus(); } throw e; } catch (SchemaException ex) { ProvisioningUtil.recordFatalError(LOGGER, result, "Can't get object with oid " + oid + ". Reason " + ex.getMessage(), ex); throw ex; } }
@Override public MidPointPrincipal getPrincipal(String username) throws ObjectNotFoundException, SchemaException { OperationResult result = new OperationResult(OPERATION_GET_PRINCIPAL); PrismObject<UserType> user = null; try { user = findByUsername(username, result); } catch (ObjectNotFoundException ex) { LOGGER.trace("Couldn't find user with name '{}', reason: {}.", new Object[]{username, ex.getMessage(), ex}); throw ex; } catch (Exception ex) { LOGGER.warn("Error getting user with name '{}', reason: {}.", new Object[]{username, ex.getMessage(), ex}); throw new SystemException(ex.getMessage(), ex); } return getPrincipal(user, null, result); }
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; }
@SuppressWarnings("rawtypes") private void saveAccountResult(ResourceObjectShadowChangeDescription shadowChangeDescription, Change change, OperationResult notifyChangeResult, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { Collection<? extends ItemDelta> shadowModification = createShadowResultModification(change, notifyChangeResult); String oid = getOidFromChange(change); // maybe better error handling is needed try { ConstraintsChecker.onShadowModifyOperation(shadowModification); repositoryService.modifyObject(ShadowType.class, oid, shadowModification, parentResult); } catch (SchemaException ex) { parentResult.recordPartialError("Couldn't modify object: schema violation: " + ex.getMessage(), ex); // throw ex; } catch (ObjectNotFoundException ex) { parentResult.recordWarning("Couldn't modify object: object not found: " + ex.getMessage(), ex); // throw ex; } catch (ObjectAlreadyExistsException ex) { parentResult.recordPartialError( "Couldn't modify object: object already exists: " + ex.getMessage(), ex); // throw ex; } }
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); }
@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()); } } }
testResult = provisioning.testResource(resourceOid, task); } catch (ObjectNotFoundException ex) { LOGGER.error("Error testing resource OID: {}: Object not found: {} ", resourceOid, ex.getMessage(), ex); RepositoryCache.exit(); throw ex;
@Test public void test329DeleteAccountPosix() throws Exception { final String TEST_NAME = "test329DeleteAccountPosix"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); // WHEN displayWhen(TEST_NAME); provisioningService.deleteObject(ShadowType.class, ACCOUNT_POSIX_MCMUTTON_OID, null, null, task, result); // THEN displayThen(TEST_NAME); try { provisioningService.getObject(ShadowType.class, ACCOUNT_POSIX_MCMUTTON_OID, null, task, result); Assert.fail("Expected exception ObjectNotFoundException, but haven't got one."); } catch (ObjectNotFoundException ex) { display("Expected exception", ex); } try { repositoryService.getObject(ShadowType.class, ACCOUNT_POSIX_MCMUTTON_OID, GetOperationOptions.createRawCollection(), result); // objType = container.getObject(); Assert.fail("Expected exception, but haven't got one."); } catch (ObjectNotFoundException ex) { display("Expected exception", ex); assertTrue(ex.getMessage().contains(ACCOUNT_POSIX_MCMUTTON_OID)); } assertShadows(16); }
private void removeTrigger(PrismObject<ObjectType> object, PrismContainerValue<TriggerType> triggerCVal, Task task, PrismContainerDefinition<TriggerType> triggerContainerDef) { ContainerDelta<TriggerType> triggerDelta = triggerContainerDef.createEmptyDelta(F_TRIGGER); triggerDelta.addValuesToDelete(triggerCVal.clone()); Collection<? extends ItemDelta> modifications = MiscSchemaUtil.createCollection(triggerDelta); // This is detached result. It will not take part of the task result. We do not really care. OperationResult result = new OperationResult(TriggerScannerTaskHandler.class.getName()+".removeTrigger"); try { repositoryService.modifyObject(object.getCompileTimeClass(), object.getOid(), modifications, result); result.computeStatus(); task.recordObjectActionExecuted(object, ChangeType.MODIFY, null); } catch (ObjectNotFoundException e) { // Object is gone. Ergo there are no triggers left. Ergo the trigger was removed. // Ergo this is not really an error. task.recordObjectActionExecuted(object, ChangeType.MODIFY, e); LOGGER.trace("Unable to remove trigger from {}: {} (but this is probably OK)", object, e.getMessage(), e); } catch (SchemaException | ObjectAlreadyExistsException e) { task.recordObjectActionExecuted(object, ChangeType.MODIFY, e); LOGGER.error("Unable to remove trigger from {}: {}", object, e.getMessage(), e); } catch (Throwable t) { task.recordObjectActionExecuted(object, ChangeType.MODIFY, t); throw t; } finally { task.markObjectActionExecutedBoundary(); // maybe OK (absolute correctness is not quite important here) } }
+ " resolution in " + contextDescription + ": " + e.getMessage(), e, ref.getOid()); } catch (SchemaException e) { throw new SchemaException("Schema error during variable " + varDesc + " resolution in "
} catch (ObjectNotFoundException ex) { display("Expected exception", ex); assertTrue(ex.getMessage().contains(ACCOUNT_SPARROW_OID));
throw new ObjectNotFoundException( "Resource reference seems to be invalid in account construction in " + getSource() + ": " + e.getMessage(), e); } catch (SecurityViolationException | CommunicationException | ConfigurationException e) {