public String store(String nuxeoLogin, Map<String, Object> fields) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { fields.put("nuxeoLogin", nuxeoLogin); fields.put("serviceName", serviceName); DocumentModel entry = session.createEntry(fields); Long id = (Long) entry.getProperty(NuxeoOAuth2Token.SCHEMA, ENTRY_ID); return id.toString(); } }); }
@Override public DocumentModel createEntryWithoutReferences(Map<String, Object> fieldMap) { init(); final Object rawid = fieldMap.get(schemaIdField); if (rawid == null) { throw new DirectoryException(String.format("Entry is missing id field '%s'", schemaIdField)); } final String id = String.valueOf(rawid); // XXX allow longs too for (SourceInfo sourceInfo : sourceInfos) { if (!sourceInfo.source.creation) { continue; } for (SubDirectoryInfo dirInfo : sourceInfo.subDirectoryInfos) { Map<String, Object> map = new HashMap<>(); map.put(dirInfo.idField, id); for (Entry<String, String> e : dirInfo.fromSource.entrySet()) { map.put(e.getValue(), fieldMap.get(e.getKey())); } dirInfo.getSession().createEntry(map); } return getEntry(id); } throw new DirectoryException(String.format("Directory '%s' has no source allowing creation", getName())); }
@Override DirectoryEntry run(Session session) { DocumentModel docEntry = session.createEntry(entry.getDocumentModel()); return new DirectoryEntry(directory.getName(), docEntry); } });
dirSession.createEntry(fields); } catch (DirectoryException e) { log.error("Unable to create entry", e);
public void createEntry() { DirectoryService ds = Framework.getService(DirectoryService.class); Framework.doPrivileged(() -> { try (Session session = ds.open(getDirectoryName())) { session.createEntry(creationEntry); creationEntry = null; showAddForm = false; entries = null; } }); }
private static void updateSubDirectoryEntry(SubDirectoryInfo dirInfo, Map<String, Object> fieldMap, String id, boolean canCreateIfOptional) { DocumentModel dirEntry = dirInfo.getSession().getEntry(id); if (dirInfo.getSession().isReadOnly() || (dirEntry != null && isReadOnlyEntry(dirEntry))) { return; } if (dirEntry == null && !canCreateIfOptional) { // entry to update doesn't belong to this directory return; } Map<String, Object> map = new HashMap<>(); map.put(dirInfo.idField, id); for (Entry<String, String> e : dirInfo.fromSource.entrySet()) { map.put(e.getValue(), fieldMap.get(e.getKey())); } if (map.size() > 1) { if (canCreateIfOptional && dirInfo.isOptional && dirEntry == null) { // if entry does not exist, create it dirInfo.getSession().createEntry(map); } else { final DocumentModel entry = BaseSession.createEntryModel(null, dirInfo.dirSchemaName, id, null); entry.setProperties(dirInfo.dirSchemaName, map); dirInfo.getSession().updateEntry(entry); } } }
@Override public NuxeoOAuthConsumer storeConsumer(NuxeoOAuthConsumer consumer) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.createEntry( Collections.singletonMap("consumerKey", consumer.consumerKey)); consumer.asDocumentModel(entry); session.updateEntry(entry); return NuxeoOAuthConsumer.createFromDirectoryEntry(entry, null); } }); }
protected NuxeoOAuth2Token storeTokenAsDirectoryEntry(NuxeoOAuth2Token aToken) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.createEntry(aToken.toMap()); return getTokenFromDirectoryEntry(entry); } }); }
protected NuxeoOAuthToken storeAccessTokenAsDirectoryEntry(NuxeoOAuthToken aToken) { DirectoryService ds = Framework.getService(DirectoryService.class); return Framework.doPrivileged(() -> { try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel entry = session.getEntry(aToken.getToken()); if (entry == null) { entry = session.createEntry(Collections.singletonMap("token", aToken.getToken())); } aToken.updateEntry(entry); session.updateEntry(entry); return getTokenFromDirectoryEntry(session.getEntry(aToken.getToken())); } }); }
public void createDirectoryEntry() { String dirName = currentDirectoryInfo.getName(); try (Session dirSession = dirService.open(dirName)) { // check if entry already exists String schema = dirService.getDirectorySchema(dirName); String idField = dirService.getDirectoryIdField(dirName); Object id = creationDirectoryEntry.getProperty(schema, idField); if (id instanceof String && dirSession.hasEntry((String) id)) { facesMessages.add(StatusMessage.Severity.ERROR, messages.get("vocabulary.entry.identifier.already.exists")); return; } setParentColumnIfNull(creationDirectoryEntry); dirSession.createEntry(creationDirectoryEntry); resetCreateDirectoryEntry(); // invalidate directory entries list currentDirectoryEntries = null; Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.added")); } }
public void createDirectoryEntry() { DirectoryService dirService = DirectoryHelper.getDirectoryService(); String dirName = getDirectoryName(); try (Session dirSession = dirService.open(dirName)) { // check if entry already exists String schema = dirService.getDirectorySchema(dirName); String idField = dirService.getDirectoryIdField(dirName); Object id = newDirectoryEntry.getProperty(schema, idField); if (id instanceof String && dirSession.hasEntry((String) id)) { facesMessages.addToControl("suggestAddNewDirectoryEntry", StatusMessage.Severity.ERROR, messages.get("vocabulary.entry.identifier.already.exists")); return; } dirSession.createEntry(newDirectoryEntry); reset(); Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.added")); } }
@Override public OAuth2ServiceProvider addProvider(String serviceName, String description, String tokenServerURL, String authorizationServerURL, String userAuthorizationURL, String clientId, String clientSecret, List<String> scopes, Boolean isEnabled) { DirectoryService ds = Framework.getService(DirectoryService.class); try (Session session = ds.open(DIRECTORY_NAME)) { DocumentModel creationEntry = BaseSession.createEntryModel(null, SCHEMA, null, null); DocumentModel entry = Framework.doPrivileged(() -> session.createEntry(creationEntry)); entry.setProperty(SCHEMA, "serviceName", serviceName); entry.setProperty(SCHEMA, "description", description); entry.setProperty(SCHEMA, "authorizationServerURL", authorizationServerURL); entry.setProperty(SCHEMA, "tokenServerURL", tokenServerURL); entry.setProperty(SCHEMA, "userAuthorizationURL", userAuthorizationURL); entry.setProperty(SCHEMA, "clientId", clientId); entry.setProperty(SCHEMA, "clientSecret", clientSecret); entry.setProperty(SCHEMA, "scopes", String.join(",", scopes)); boolean enabled = (clientId != null && clientSecret != null); entry.setProperty(SCHEMA, "enabled", Boolean.valueOf(enabled && (isEnabled == null ? false : isEnabled))); if (!enabled) { log.info("OAuth2 provider for " + serviceName + " is disabled because clientId and/or clientSecret are empty"); } Framework.doPrivileged(() -> session.updateEntry(entry)); return getProvider(serviceName); } }