Search in sources :

Example 21 with Services

use of org.structr.core.Services in project structr by structr.

the class IndexingTest method start.

@BeforeClass
public static void start() {
    Services.enableUpdateIndexConfiguration();
    final Date now = new Date();
    final long timestamp = now.getTime();
    basePath = "/tmp/structr-test-" + timestamp;
    Settings.Services.setValue("NodeService LogService HttpService SchemaService");
    Settings.ConnectionUrl.setValue(Settings.TestingConnectionUrl.getValue());
    // example for new configuration setup
    Settings.BasePath.setValue(basePath);
    Settings.DatabasePath.setValue(basePath + "/db");
    Settings.FilesPath.setValue(basePath + "/files");
    Settings.RelationshipCacheSize.setValue(1000);
    Settings.NodeCacheSize.setValue(1000);
    Settings.SuperUserName.setValue("superadmin");
    Settings.SuperUserPassword.setValue("sehrgeheim");
    Settings.ApplicationTitle.setValue("structr unit test app" + timestamp);
    Settings.ApplicationHost.setValue(host);
    Settings.HttpPort.setValue(httpPort);
    Settings.Servlets.setValue("JsonRestServlet");
    Settings.RestAuthenticator.setValue(SuperUserAuthenticator.class.getName());
    Settings.RestResourceProvider.setValue(DefaultResourceProvider.class.getName());
    Settings.RestServletPath.setValue(restUrl);
    Settings.RestUserClass.setValue("");
    final Services services = Services.getInstance();
    // wait for service layer to be initialized
    do {
        try {
            Thread.sleep(100);
        } catch (Throwable t) {
        }
    } while (!services.isInitialized());
    securityContext = SecurityContext.getSuperUserInstance();
    app = StructrApp.getInstance(securityContext);
    sleep(10000L);
}
Also used : Services(org.structr.core.Services) SuperUserAuthenticator(org.structr.core.auth.SuperUserAuthenticator) Date(java.util.Date) DefaultResourceProvider(org.structr.rest.DefaultResourceProvider) BeforeClass(org.junit.BeforeClass)

Example 22 with Services

use of org.structr.core.Services in project structr by structr.

the class StructrGraphQLTest method start.

@BeforeClass
public static void start() {
    final Date now = new Date();
    final long timestamp = now.getTime();
    basePath = "/tmp/structr-test-" + timestamp;
    Settings.Services.setValue("NodeService LogService HttpService SchemaService");
    Settings.ConnectionUrl.setValue(Settings.TestingConnectionUrl.getValue());
    // example for new configuration setup
    Settings.BasePath.setValue(basePath);
    Settings.DatabasePath.setValue(basePath + "/db");
    Settings.FilesPath.setValue(basePath + "/files");
    Settings.RelationshipCacheSize.setValue(1000);
    Settings.NodeCacheSize.setValue(1000);
    Settings.SuperUserName.setValue("superadmin");
    Settings.SuperUserPassword.setValue("sehrgeheim");
    Settings.ApplicationTitle.setValue("structr unit test app" + timestamp);
    Settings.ApplicationHost.setValue(host);
    Settings.HttpPort.setValue(httpPort);
    Settings.Servlets.setValue("GraphQLServlet");
    Settings.GraphQLAuthenticator.setValue(SuperUserAuthenticator.class.getName());
    Settings.GraphQLResourceProvider.setValue(DefaultResourceProvider.class.getName());
    Settings.GraphQLServletPath.setValue(restUrl);
    // Settings.LogSchemaOutput.setValue(true);
    final Services services = Services.getInstance();
    // wait for service layer to be initialized
    do {
        try {
            Thread.sleep(100);
        } catch (Throwable t) {
        }
    } while (!services.isInitialized());
    securityContext = SecurityContext.getSuperUserInstance();
    app = StructrApp.getInstance(securityContext);
    // sleep again to wait for schema initialization
    try {
        Thread.sleep(2000);
    } catch (Throwable t) {
    }
}
Also used : Services(org.structr.core.Services) SuperUserAuthenticator(org.structr.core.auth.SuperUserAuthenticator) Date(java.util.Date) DefaultResourceProvider(org.structr.rest.DefaultResourceProvider) BeforeClass(org.junit.BeforeClass)

Example 23 with Services

use of org.structr.core.Services in project structr by structr.

the class LicensingTest method startSystem.

@BeforeClass
public static void startSystem() {
    Services.disableTestingMode();
    final Date now = new Date();
    final long timestamp = now.getTime();
    basePath = "/tmp/structr-test-" + timestamp;
    Settings.Services.setValue("NodeService LogService SchemaService");
    Settings.ConnectionUrl.setValue(Settings.TestingConnectionUrl.getValue());
    // example for new configuration setup
    Settings.BasePath.setValue(basePath);
    Settings.DatabasePath.setValue(basePath + "/db");
    Settings.FilesPath.setValue(basePath + "/files");
    Settings.RelationshipCacheSize.setValue(1000);
    Settings.NodeCacheSize.setValue(1000);
    Settings.SuperUserName.setValue("superadmin");
    Settings.SuperUserPassword.setValue("sehrgeheim");
    final Services services = Services.getInstance();
    // wait for service layer to be initialized
    do {
        try {
            Thread.sleep(100);
        } catch (Throwable t) {
        }
    } while (!services.isInitialized());
    securityContext = SecurityContext.getSuperUserInstance();
    app = StructrApp.getInstance(securityContext);
}
Also used : Services(org.structr.core.Services) Date(java.util.Date) BeforeClass(org.junit.BeforeClass)

Example 24 with Services

use of org.structr.core.Services in project structr by structr.

the class RestAuthenticator method initializeAndExamineRequest.

// ~--- methods --------------------------------------------------------
/**
 * Examine request and try to find a user.
 *
 * First, check session id, then try external (OAuth) authentication,
 * finally, check standard login by credentials.
 *
 * @param request
 * @param response
 * @return security context
 * @throws FrameworkException
 */
@Override
public SecurityContext initializeAndExamineRequest(final HttpServletRequest request, final HttpServletResponse response) throws FrameworkException {
    SecurityContext securityContext;
    Principal user = SessionHelper.checkSessionAuthentication(request);
    if (user == null) {
        user = getUser(request, true);
    }
    if (user == null) {
        // If no user could be determined, assume frontend access
        securityContext = SecurityContext.getInstance(user, request, AccessMode.Frontend);
    } else {
        if (user instanceof SuperUser) {
            securityContext = SecurityContext.getSuperUserInstance(request);
        } else {
            securityContext = SecurityContext.getInstance(user, request, AccessMode.Backend);
            SessionHelper.clearInvalidSessions(user);
        }
    }
    securityContext.setAuthenticator(this);
    // Check CORS settings (Cross-origin resource sharing, see http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
    final String origin = request.getHeader("Origin");
    if (!StringUtils.isBlank(origin)) {
        final Services services = Services.getInstance();
        response.setHeader("Access-Control-Allow-Origin", origin);
        // allow cross site resource sharing (read only)
        final String maxAge = Settings.AccessControlMaxAge.getValue();
        if (StringUtils.isNotBlank(maxAge)) {
            response.setHeader("Access-Control-MaxAge", maxAge);
        }
        final String allowMethods = Settings.AccessControlAllowMethods.getValue();
        if (StringUtils.isNotBlank(allowMethods)) {
            response.setHeader("Access-Control-Allow-Methods", allowMethods);
        }
        final String allowHeaders = Settings.AccessControlAllowHeaders.getValue();
        if (StringUtils.isNotBlank(allowHeaders)) {
            response.setHeader("Access-Control-Allow-Headers", allowHeaders);
        }
        final String allowCredentials = Settings.AccessControlAllowCredentials.getValue();
        if (StringUtils.isNotBlank(allowCredentials)) {
            response.setHeader("Access-Control-Allow-Credentials", allowCredentials);
        }
        final String exposeHeaders = Settings.AccessControlExposeHeaders.getValue();
        if (StringUtils.isNotBlank(exposeHeaders)) {
            response.setHeader("Access-Control-Expose-Headers", exposeHeaders);
        }
    }
    examined = true;
    return securityContext;
}
Also used : Services(org.structr.core.Services) SecurityContext(org.structr.common.SecurityContext) SuperUser(org.structr.core.entity.SuperUser) Principal(org.structr.core.entity.Principal)

Example 25 with Services

use of org.structr.core.Services in project structr by structr.

the class HtmlServletObjectResolvingTest method start.

public static void start(final Map<String, Object> additionalConfig) {
    final long timestamp = System.currentTimeMillis();
    basePath = "/tmp/structr-test-" + timestamp + "-" + System.nanoTime();
    Settings.HtmlResolveProperties.setValue("TestOne.anInt, TestOne.aString, TestOne.aDouble");
    Settings.Services.setValue("NodeService HttpService SchemaService");
    Settings.ConnectionUrl.setValue(Settings.TestingConnectionUrl.getValue());
    // example for new configuration setup
    Settings.BasePath.setValue(basePath);
    Settings.DatabasePath.setValue(basePath + "/db");
    Settings.FilesPath.setValue(basePath + "/files");
    Settings.RelationshipCacheSize.setValue(1000);
    Settings.NodeCacheSize.setValue(1000);
    Settings.SuperUserName.setValue("superadmin");
    Settings.SuperUserPassword.setValue("sehrgeheim");
    Settings.ApplicationTitle.setValue("structr unit test app" + timestamp);
    Settings.ApplicationHost.setValue(host);
    Settings.HttpPort.setValue(httpPort);
    Settings.Servlets.setValue("JsonRestServlet WebSocketServlet HtmlServlet");
    final Services services = Services.getInstance();
    // wait for service layer to be initialized
    do {
        try {
            Thread.sleep(100);
        } catch (Throwable t) {
        }
    } while (!services.isInitialized());
    securityContext = SecurityContext.getSuperUserInstance();
    app = StructrApp.getInstance(securityContext);
    graphDbCommand = app.command(GraphDatabaseCommand.class);
}
Also used : Services(org.structr.core.Services) GraphDatabaseCommand(org.structr.core.graph.GraphDatabaseCommand)

Aggregations

Services (org.structr.core.Services)30 BeforeClass (org.junit.BeforeClass)21 Date (java.util.Date)20 SuperUserAuthenticator (org.structr.core.auth.SuperUserAuthenticator)5 DefaultResourceProvider (org.structr.rest.DefaultResourceProvider)5 GraphDatabaseCommand (org.structr.core.graph.GraphDatabaseCommand)4 Tx (org.structr.core.graph.Tx)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 HttpSession (javax.servlet.http.HttpSession)1 Task (org.structr.agent.Task)1 SettingsGroup (org.structr.api.config.SettingsGroup)1 Service (org.structr.api.service.Service)1 StructrServices (org.structr.api.service.StructrServices)1 Attr (org.structr.api.util.html.Attr)1 Document (org.structr.api.util.html.Document)1 Tag (org.structr.api.util.html.Tag)1 SecurityContext (org.structr.common.SecurityContext)1 DatabaseServiceNotAvailableException (org.structr.common.error.DatabaseServiceNotAvailableException)1 FrameworkException (org.structr.common.error.FrameworkException)1