checkSessionId(userId, sessionId); } else { if (configuration.getAdmin().getPassword() == null || configuration.getAdmin().getPassword().isEmpty()) { throw new CatalogException("Nor the administrator password nor the session id could be found. The user could not be " + "deleted."); .authenticate("admin", configuration.getAdmin().getPassword(), true);
public void deleteCatalogDB(boolean force) throws CatalogException, URISyntaxException { if (!force) { userManager.validatePassword("admin", configuration.getAdmin().getPassword(), true); } catalogDBAdaptorFactory.deleteCatalogDB(); clearCatalog(); }
@Override public String getAdminPassword() throws CatalogDBException { Bson query = METADATA_QUERY; QueryResult<Document> queryResult = metaCollection.find(query, new QueryOptions(QueryOptions.INCLUDE, "admin")); return parseObject((Document) queryResult.first().get("admin"), Admin.class).getPassword(); }
public QueryResult<User> update(String userId, ObjectMap parameters, QueryOptions options, String sessionId) throws CatalogException { ParamUtils.checkParameter(userId, "userId"); ParamUtils.checkObj(parameters, "parameters"); if (sessionId != null && !sessionId.isEmpty()) { ParamUtils.checkParameter(sessionId, "sessionId"); checkSessionId(userId, sessionId); for (String s : parameters.keySet()) { if (!s.matches("name|email|organization|attributes")) { throw new CatalogDBException("Parameter '" + s + "' can't be changed"); } } } else { if (configuration.getAdmin().getPassword() == null || configuration.getAdmin().getPassword().isEmpty()) { throw new CatalogException("Nor the administrator password nor the session id could be found. The user could not be " + "updated."); } authenticationManagerMap.get(INTERNAL_AUTHORIZATION).authenticate("admin", configuration.getAdmin().getPassword(), true); } if (parameters.containsKey("email")) { checkEmail(parameters.getString("email")); } userDBAdaptor.updateUserLastModified(userId); QueryResult<User> queryResult = userDBAdaptor.update(userId, parameters); auditManager.recordUpdate(AuditRecord.Resource.user, userId, userId, parameters, null, null); return queryResult; }
/** * Populates the database with dummy data. * * @param configuration Catalog configuration file. * @param force Used in the case where a database already exists with the same name. When force = true, it will override it. * @throws CatalogException when there is already a database with the same name and force is false. * @throws URISyntaxException when there is a problem parsing the URI read from the configuration file. */ public static void createDemoDatabase(Configuration configuration, boolean force) throws CatalogException, URISyntaxException { CatalogManager catalogManager = new CatalogManager(configuration); if (catalogManager.existsCatalogDB()) { if (force) { catalogManager.deleteCatalogDB(force); } else { // throw new CatalogException("A database called " + catalogConfiguration.getDatabase().getDatabase() + " already exists"); throw new CatalogException("A database called " + catalogManager.getCatalogDatabase() + " already exists"); } } catalogManager.installCatalogDB(configuration.getAdmin().getSecretKey(), configuration.getAdmin().getPassword()); try { populateDatabase(catalogManager); } catch (IOException e) { throw new CatalogException(e.getMessage()); } }
public void initializeMetaCollection(Configuration configuration) throws CatalogException { Admin admin = configuration.getAdmin(); admin.setPassword(CatalogAuthenticationManager.cypherPassword(admin.getPassword())); Metadata metadata = new Metadata().setIdCounter(configuration.getCatalog().getOffset()).setVersion(VERSION); Document metadataObject = getMongoDBDocument(metadata, "Metadata"); metadataObject.put(PRIVATE_ID, MongoDBAdaptorFactory.METADATA_OBJECT_ID); Document adminDocument = getMongoDBDocument(admin, "Admin"); metadataObject.put("admin", adminDocument); metaCollection.insert(metadataObject, null); }