@Override public String toString() { return "SQLSession [directory=" + directory.getName() + ", sid=" + sid + "]"; }
public String getName() { return directory.getName(); }
@Override // useful for the log function public String toString() { return String.format("LDAPSession '%s' for directory %s", sid, directory.getName()); }
private void acquireConnection() { try { if (sqlConnection == null || sqlConnection.isClosed()) { sqlConnection = getDirectory().getConnection(); } } catch (SQLException e) { throw new DirectoryException( "Cannot connect to SQL directory '" + directory.getName() + "': " + e.getMessage(), e); } }
@Override DirectoryEntry run(Session session) { DocumentModel docEntry = session.createEntry(entry.getDocumentModel()); return new DirectoryEntry(directory.getName(), docEntry); } });
@Override public List<DirectoryEntry> getCurrentPage() { Object[] parameters = getParameters(); if (parameters == null || parameters.length > 1) { throw new IllegalStateException("Invalid parameters: " + Arrays.toString(parameters)); } if (!(parameters[0] instanceof Directory)) { throw new IllegalStateException("Provided parameter is not a Directory: " + parameters[0]); } Directory directory = (Directory) parameters[0]; try (Session session = directory.getSession()) { return session.query(Collections.emptyMap(), Collections.emptySet(), Collections.emptyMap(), false, (int) getPageSize(), (int) getCurrentPageOffset()) .stream() .map(dir -> new DirectoryEntry(directory.getName(), dir)) .collect(Collectors.toList()); } } }
void checkEditGuards() { NuxeoPrincipal currentUser = getContext().getCoreSession().getPrincipal(); if (!(currentUser.isAdministrator() || currentUser.isMemberOf("powerusers"))) { throw new WebSecurityException("Not allowed to edit directory"); } UserManager um = Framework.getService(UserManager.class); if (directory.getName().equals(um.getUserDirectoryName()) || directory.getName().equals(um.getGroupDirectoryName())) { throw new NuxeoException("Not allowed to edit user/group directories, please use user/group endpoints", SC_BAD_REQUEST); } }
Session dirSession = dir.getSession(); dirSession.close(); dirName = dir.getName(); } catch (DirectoryException e) { success = false;
@Override public DocumentModel adapt(Directory directory, DocumentModel entry) { if (fieldName == null || pattern == null) { log.warn(getClass().getName() + " is missing configuration parameters"); return entry; } if (BaseSession.isReadOnlyEntry(entry)) { // keep already existing flag return entry; } try { Object fieldValue = entry.getProperty(directory.getSchema(), fieldName); String value = fieldValue != null ? fieldValue.toString() : ""; if (pattern.matcher(value).matches()) { BaseSession.setReadWriteEntry(entry); } else { BaseSession.setReadOnlyEntry(entry); } } catch (PropertyException e) { throw new DirectoryException( String.format( "The field '%s' of entry '%s' could not be adapt and map on directory '%s', check that the field exist in the schema", fieldName, entry.getId(), directory.getName()), e); } return entry; }
@Override Object run(Session session) { DocumentModel entry = session.getEntry(entryId); if (entry == null) { throw new WebResourceNotFoundException("Entry not found"); } return newObject("directoryEntry", new DirectoryEntry(directory.getName(), entry), entryId); } });
protected BaseSession(Directory directory, Class<? extends Reference> referenceClass) { this.directory = directory; schemaName = directory.getSchema(); directoryName = directory.getName(); BaseDirectoryDescriptor desc = directory.getDescriptor(); substringMatchType = desc.getSubstringMatchType(); autoincrementId = desc.isAutoincrementIdField(); permissions = desc.permissions; passwordHashAlgorithm = desc.passwordHashAlgorithm; this.referenceClass = referenceClass; computeMultiTenantId = desc.isComputeMultiTenantId(); }
if (field == null) { String message = String.format("Invalid field name '%s' for directory '%s' with schema '%s'", fieldName, directory.getName(), directory.getSchema()); throw new DirectoryException(message);
@Override DirectoryEntry run(Session session) { try { DocumentModel docEntry = entry.getDocumentModel(); session.updateEntry(docEntry); return new DirectoryEntry(directory.getName(), session.getEntry(docEntry.getId())); } catch (DirectoryException e) { throw new NuxeoException(e.getMessage(), SC_BAD_REQUEST); } } });
log.warn("Directory " + getDirectory().getName() + " cannot update field " + referenceFieldName + " for entry " + docModel.getId() + ": this field is associated with more than one reference");