use of org.bimserver.models.store.ServerSettings in project BIMserver by opensourceBIM.
the class SetServerSettingDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
ServerSettings serverSettings = getDatabaseSession().getSingle(StorePackage.eINSTANCE.getServerSettings(), OldQuery.getDefault());
serverSettingsSetter.set(serverSettings);
getDatabaseSession().store(serverSettings);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getServerSettingsCache().updateCache();
}
});
return null;
}
use of org.bimserver.models.store.ServerSettings in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method registerApplication.
@Override
public Long registerApplication(String registrationEndpoint, String apiUrl, String redirectUrl) throws UserException, ServerException {
try {
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_RegistrationEndpoint(), registrationEndpoint);
if (oAuthServer != null) {
return oAuthServer.getOid();
}
ServerSettings serverSettings = getBimServer().getServerSettingsCache().getServerSettings();
OAuthClientRequest request = OAuthClientRegistrationRequest.location(registrationEndpoint, OAuthRegistration.Type.PUSH).setName(serverSettings.getName()).setUrl(redirectUrl).setDescription(serverSettings.getDescription()).setIcon(serverSettings.getIcon()).setRedirectURL(redirectUrl).buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
oAuthServer = session.create(OAuthServer.class);
oAuthServer.setApiUrl(apiUrl);
oAuthServer.setClientId(response.getClientId());
oAuthServer.setClientSecret(response.getClientSecret());
oAuthServer.setIssuedAt(new Date(Long.parseLong(response.getIssuedAt())));
GregorianCalendar expiresAt = new GregorianCalendar();
expiresAt.setTimeInMillis(new GregorianCalendar().getTimeInMillis() + response.getExpiresIn());
oAuthServer.setExpiresAt(expiresAt.getTime());
oAuthServer.setRegistrationEndpoint(registrationEndpoint);
oAuthServer.setClientDescription(serverSettings.getDescription());
oAuthServer.setClientName(serverSettings.getName());
if (serverSettings.getIcon() != null) {
byte[] icon = NetUtils.getContentAsBytes(new URL(serverSettings.getIcon()), 500);
oAuthServer.setClientIcon(icon);
}
oAuthServer.setIncoming(false);
oAuthServer.setRedirectUrl(redirectUrl);
session.commit();
return oAuthServer.getOid();
}
} catch (Exception e) {
return handleException(e);
}
}
use of org.bimserver.models.store.ServerSettings in project BIMserver by opensourceBIM.
the class SetServerSettingsDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
ServerSettings existingServerSettings = getDatabaseSession().getSingle(StorePackage.eINSTANCE.getServerSettings(), OldQuery.getDefault());
existingServerSettings.getWhitelistedDomains().clear();
new SConverter().convertFromSObject(serverSettings, existingServerSettings, getDatabaseSession());
getDatabaseSession().store(existingServerSettings);
return null;
}
use of org.bimserver.models.store.ServerSettings in project BIMserver by opensourceBIM.
the class Database method createDefaultSettings.
public ServerSettings createDefaultSettings(DatabaseSession databaseSession) throws BimserverDatabaseException {
ServerSettings settings = databaseSession.create(ServerSettings.class);
settings.setEmailSenderAddress("no-reply@bimserver.org");
settings.setEmailSenderName("Administrator");
settings.setSiteAddress("");
settings.setSmtpServer("");
settings.setSmtpPort(25);
settings.setSmtpProtocol(SmtpProtocol.SMTP);
settings.setProtocolBuffersPort(-1);
settings.setAllowCreateValidatedUser(true);
settings.setAllowSelfRegistration(false);
settings.setAllowUsersToCreateTopLevelProjects(false);
settings.setCheckinMergingEnabled(false);
settings.setHideUserListForNonAdmin(true);
settings.setCacheOutputFiles(true);
settings.setServiceRepositoryUrl("https://raw.githubusercontent.com/opensourceBIM/BIMserver-Repository/master");
settings.setAllowOnlyWhitelisted(false);
settings.setGenerateGeometryOnCheckin(true);
settings.setReuseGeometry(true);
settings.setStoreLastLogin(false);
settings.setRenderEngineProcesses(Runtime.getRuntime().availableProcessors());
// 1 month
settings.setSessionTimeOutSeconds(60 * 60 * 24 * 30);
settings.getWhitelistedDomains().add("localhost");
settings.getWhitelistedDomains().add("localhost:8080");
settings.setPluginStrictVersionChecking(true);
settings.setOptimizeMappedItems(false);
return settings;
}
use of org.bimserver.models.store.ServerSettings in project BIMserver by opensourceBIM.
the class Database method init.
public void init() throws DatabaseInitException, DatabaseRestartRequiredException, InconsistentModelsException {
DatabaseSession databaseSession = createSession();
try {
if (getKeyValueStore().isNew()) {
keyValueStore.createTable(CLASS_LOOKUP_TABLE, null, true);
keyValueStore.createTable(Database.STORE_PROJECT_NAME, null, true);
keyValueStore.createTable(Registry.REGISTRY_TABLE, null, true);
setDatabaseVersion(-1, databaseSession);
created = new Date();
registry.save(DATE_CREATED, created, databaseSession);
} else {
keyValueStore.openTable(databaseSession, CLASS_LOOKUP_TABLE, true);
keyValueStore.openTable(databaseSession, Database.STORE_PROJECT_NAME, true);
keyValueStore.openTable(databaseSession, Registry.REGISTRY_TABLE, true);
created = registry.readDate(DATE_CREATED, databaseSession);
if (created == null) {
created = new Date();
registry.save(DATE_CREATED, created, databaseSession);
}
}
databaseSchemaVersion = registry.readInt(SCHEMA_VERSION, databaseSession, -1);
migrator = new Migrator(this);
if (getKeyValueStore().isNew()) {
try {
migrator.migrate(databaseSession);
} catch (MigrationException e) {
LOGGER.error("", e);
}
registry.save("isnew", true, databaseSession);
databaseSession.commit();
databaseSession.close();
throw new DatabaseRestartRequiredException();
} else if (registry.readBoolean("isnew", true, databaseSession)) {
initInternalStructure(databaseSession);
initCounters(databaseSession);
ServerSettings settings = createDefaultSettings(databaseSession);
databaseSession.store(settings);
new CreateBaseProjectDatabaseAction(databaseSession, AccessMethod.INTERNAL).execute();
AddUserDatabaseAction addUserDatabaseAction = new AddUserDatabaseAction(bimServer, databaseSession, AccessMethod.INTERNAL, "system", "system", "System", UserType.SYSTEM, new SystemAuthorization(1, TimeUnit.HOURS), false, null);
addUserDatabaseAction.setCreateSystemUser();
User systemUser = addUserDatabaseAction.execute();
systemUser.setCreatedBy(systemUser);
databaseSession.store(systemUser);
DatabaseCreated databaseCreated = databaseSession.create(DatabaseCreated.class);
databaseCreated.setAccessMethod(AccessMethod.INTERNAL);
databaseCreated.setExecutor(systemUser);
databaseCreated.setDate(new Date());
databaseCreated.setPath(getKeyValueStore().getLocation());
databaseCreated.setVersion(databaseSchemaVersion);
databaseSession.store(databaseCreated);
registry.save("isnew", false, databaseSession);
} else {
initInternalStructure(databaseSession);
initCounters(databaseSession);
}
for (EClass eClass : cidToEclass) {
if (eClass != null) {
if (eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE) {
realClasses.add(eClass.getName());
}
}
}
databaseSession.commit();
} catch (UserException e) {
LOGGER.error("", e);
close();
throw new DatabaseInitException(e.getMessage());
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
close();
throw new DatabaseInitException(e.getMessage());
} catch (DatabaseRestartRequiredException e) {
throw e;
} catch (Exception e) {
throw new DatabaseInitException(e);
} finally {
databaseSession.close();
}
}
Aggregations