Search in sources :

Example 11 with ServerSettings

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;
}
Also used : ServerSettings(org.bimserver.models.store.ServerSettings) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException)

Example 12 with ServerSettings

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);
    }
}
Also used : OAuthRegistrationClient(org.apache.oltu.oauth2.ext.dynamicreg.client.OAuthRegistrationClient) DatabaseSession(org.bimserver.database.DatabaseSession) OAuthClientRegistrationResponse(org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse) ServerSettings(org.bimserver.models.store.ServerSettings) GregorianCalendar(java.util.GregorianCalendar) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) SOAuthServer(org.bimserver.interfaces.objects.SOAuthServer) OAuthServer(org.bimserver.models.store.OAuthServer) Date(java.util.Date) URL(java.net.URL) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 13 with ServerSettings

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;
}
Also used : SConverter(org.bimserver.interfaces.SConverter) SServerSettings(org.bimserver.interfaces.objects.SServerSettings) ServerSettings(org.bimserver.models.store.ServerSettings)

Example 14 with ServerSettings

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;
}
Also used : ServerSettings(org.bimserver.models.store.ServerSettings)

Example 15 with ServerSettings

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();
    }
}
Also used : User(org.bimserver.models.store.User) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) Date(java.util.Date) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) MigrationException(org.bimserver.database.migrations.MigrationException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) MigrationException(org.bimserver.database.migrations.MigrationException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) DatabaseCreated(org.bimserver.models.log.DatabaseCreated) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) AddUserDatabaseAction(org.bimserver.database.actions.AddUserDatabaseAction) ServerSettings(org.bimserver.models.store.ServerSettings) CreateBaseProjectDatabaseAction(org.bimserver.database.actions.CreateBaseProjectDatabaseAction) UserException(org.bimserver.shared.exceptions.UserException) Migrator(org.bimserver.database.migrations.Migrator)

Aggregations

ServerSettings (org.bimserver.models.store.ServerSettings)29 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)21 DatabaseSession (org.bimserver.database.DatabaseSession)21 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)18 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)18 SServerSettings (org.bimserver.interfaces.objects.SServerSettings)18 UserException (org.bimserver.shared.exceptions.UserException)10 User (org.bimserver.models.store.User)5 ServerException (org.bimserver.shared.exceptions.ServerException)5 Date (java.util.Date)4 HashMap (java.util.HashMap)3 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)3 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 Map (java.util.Map)2 InternetAddress (javax.mail.internet.InternetAddress)2 PostCommitAction (org.bimserver.database.PostCommitAction)2 DatabaseInitException (org.bimserver.database.berkeley.DatabaseInitException)2