Search in sources :

Example 21 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class Template method renderContent.

/*
	public static final org.structr.common.View uiView                                   = new org.structr.common.View(Content.class, PropertyView.Ui,
		children, childrenIds, content, contentType, parent, pageId, hideOnDetail, hideOnIndex, sharedComponent, syncedNodes, dataKey, restQuery, cypherQuery, xpathQuery, functionQuery,
		showForLocales, hideForLocales, showConditions, hideConditions, isContent
	);

	public static final org.structr.common.View publicView                               = new org.structr.common.View(Content.class, PropertyView.Public,
		children, childrenIds, content, contentType, parent, pageId, hideOnDetail, hideOnIndex, sharedComponent, syncedNodes, dataKey, restQuery, cypherQuery, xpathQuery, functionQuery,
		showForLocales, hideForLocales, showConditions, hideConditions, isContent
	);
	*/
public static void renderContent(final Template thisTemplate, final RenderContext renderContext, final int depth) throws FrameworkException {
    final SecurityContext securityContext = thisTemplate.getSecurityContext();
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (EditMode.DEPLOYMENT.equals(editMode)) {
        final DOMNode _syncedNode = thisTemplate.getSharedComponent();
        final AsyncBuffer out = renderContext.getBuffer();
        if (depth > 0) {
            out.append(DOMNode.indent(depth, renderContext));
        }
        DOMNode.renderDeploymentExportComments(thisTemplate, out, true);
        out.append("<structr:template src=\"");
        if (_syncedNode != null) {
            // use name of synced node
            final String _name = _syncedNode.getProperty(AbstractNode.name);
            out.append(_name != null ? _name.concat("-").concat(_syncedNode.getUuid()) : _syncedNode.getUuid());
        } else {
            // use name of local template
            final String _name = thisTemplate.getProperty(AbstractNode.name);
            out.append(_name != null ? _name.concat("-").concat(thisTemplate.getUuid()) : thisTemplate.getUuid());
        }
        out.append("\"");
        DOMNode.renderSharedComponentConfiguration(thisTemplate, out, editMode);
        // include custom attributes in templates as well!
        DOMNode.renderCustomAttributes(thisTemplate, out, securityContext, renderContext);
        out.append(">");
        // fetch children
        final List<RelationshipInterface> rels = thisTemplate.getChildRelationships();
        if (rels.isEmpty()) {
            // No child relationships, maybe this node is in sync with another node
            if (_syncedNode != null) {
                rels.addAll(_syncedNode.getChildRelationships());
            }
        }
        for (final RelationshipInterface rel : rels) {
            final DOMNode subNode = (DOMNode) rel.getTargetNode();
            subNode.render(renderContext, depth + 1);
        }
        out.append(DOMNode.indent(depth, renderContext));
        out.append("</structr:template>");
        out.append(DOMNode.indent(depth - 1, renderContext));
    } else {
        // "super" call using static method..
        Content.renderContent(thisTemplate, renderContext, depth);
    }
}
Also used : SecurityContext(org.structr.common.SecurityContext) RelationshipInterface(org.structr.core.graph.RelationshipInterface) EditMode(org.structr.web.common.RenderContext.EditMode) AsyncBuffer(org.structr.web.common.AsyncBuffer)

Example 22 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class AnalyzeSourceTreeFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    try {
        if (!(arrayHasLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof String)) {
            return null;
        }
        final SecurityContext securityContext = ctx.getSecurityContext();
        final App app = StructrApp.getInstance(securityContext);
        new JavaParserModule().analyzeSourceTree(app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), (String) sources[0]).getFirst());
    } catch (final IllegalArgumentException e) {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
        return usage(ctx.isJavaScriptContext());
    }
    return "";
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SecurityContext(org.structr.common.SecurityContext) Folder(org.structr.web.entity.Folder)

Example 23 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class StructrCMISServicesFactory method checkAuthentication.

// ----- private methods -----
private SecurityContext checkAuthentication(final CallContext callContext) {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final String username = callContext.getUsername();
        final String password = callContext.getPassword();
        final Principal principal = AuthHelper.getPrincipalForPassword(Principal.name, username, password);
        SecurityContext securityContext = null;
        if (principal != null) {
            if (principal instanceof SuperUser) {
                securityContext = SecurityContext.getSuperUserInstance();
            } else {
                securityContext = SecurityContext.getInstance(principal, AccessMode.Backend);
            }
        }
        tx.success();
        if (securityContext != null) {
            return securityContext;
        }
    } catch (AuthenticationException aex) {
        throw new CmisUnauthorizedException(aex.getMessage());
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    throw new CmisUnauthorizedException();
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AuthenticationException(org.structr.core.auth.exception.AuthenticationException) SecurityContext(org.structr.common.SecurityContext) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) SuperUser(org.structr.core.entity.SuperUser) Principal(org.structr.core.entity.Principal)

Example 24 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class UiAuthenticator method initializeAndExamineRequest.

/**
 * 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 {
    Principal user = SessionHelper.checkSessionAuthentication(request);
    SecurityContext securityContext;
    if (user == null) {
        user = checkExternalAuthentication(request, response);
    }
    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);
        }
    }
    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)) {
        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;
    // store a reference of the response object in SecurityContext
    // to be able to stream data directly from builtin functions
    securityContext.setResponse(response);
    // expose Structr edition
    response.setHeader("X-Structr-Edition", Services.getInstance().getEdition());
    return securityContext;
}
Also used : SecurityContext(org.structr.common.SecurityContext) SuperUser(org.structr.core.entity.SuperUser) Principal(org.structr.core.entity.Principal)

Example 25 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class File method onModification.

static void onModification(final File thisFile, final SecurityContext securityContext, final ErrorBuffer errorBuffer, final ModificationQueue modificationQueue) throws FrameworkException {
    synchronized (thisFile) {
        // save current security context
        final SecurityContext previousSecurityContext = securityContext;
        // replace with SU context
        thisFile.setSecurityContext(SecurityContext.getSuperUserInstance());
        // update metadata and parent as superuser
        FileHelper.updateMetadata(thisFile, false);
        // restore previous security context
        thisFile.setSecurityContext(previousSecurityContext);
    }
    thisFile.triggerMinificationIfNeeded(modificationQueue);
}
Also used : SecurityContext(org.structr.common.SecurityContext)

Aggregations

SecurityContext (org.structr.common.SecurityContext)131 FrameworkException (org.structr.common.error.FrameworkException)76 App (org.structr.core.app.App)56 StructrApp (org.structr.core.app.StructrApp)56 Tx (org.structr.core.graph.Tx)36 GraphObject (org.structr.core.GraphObject)35 PropertyKey (org.structr.core.property.PropertyKey)26 PropertyMap (org.structr.core.property.PropertyMap)26 AbstractNode (org.structr.core.entity.AbstractNode)19 IOException (java.io.IOException)18 Map (java.util.Map)17 File (org.structr.web.entity.File)14 LinkedList (java.util.LinkedList)13 DatabaseService (org.structr.api.DatabaseService)12 DOMNode (org.structr.web.entity.dom.DOMNode)12 Result (org.structr.core.Result)11 PropertyConverter (org.structr.core.converter.PropertyConverter)11 GraphObjectMap (org.structr.core.GraphObjectMap)10 Query (org.structr.core.app.Query)10 Principal (org.structr.core.entity.Principal)10