String getSecretKey() { if (StringUtils.isEmpty(secretKey)) { secretKey = configuration.getAdmin().getSecretKey(); } return secretKey; }
JwtManager(Configuration configuration) { this.configuration = configuration; this.secretKey = this.configuration.getAdmin().getSecretKey(); this.expiration = this.configuration.getAuthentication().getExpiration(); logger = LoggerFactory.getLogger(JwtManager.class); }
private void initializeAdmin() throws CatalogDBException { if (StringUtils.isEmpty(this.configuration.getAdmin().getSecretKey())) { this.configuration.getAdmin().setSecretKey(this.catalogDBAdaptorFactory.getCatalogMetaDBAdaptor().readSecretKey()); } this.configuration.getAdmin().setAlgorithm("HS256"); // if (StringUtils.isEmpty(this.configuration.getAdmin().getAlgorithm())) { // this.configuration.getAdmin().setAlgorithm(this.catalogDBAdaptorFactory.getCatalogMetaDBAdaptor().readAlgorithm()); // } }
@Override public String readSecretKey() throws CatalogDBException { Bson query = METADATA_QUERY; QueryResult queryResult = this.metaCollection.find(query, new QueryOptions("include", "admin")); if (queryResult.getNumResults() == 1) { return (MongoDBUtils.parseObject((Document) ((Document) queryResult.first()).get("admin"), Admin.class)).getSecretKey(); } return ""; }
/** * 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()); } }