Search in sources :

Example 1 with SemanticErrorToken

use of org.structr.common.error.SemanticErrorToken in project structr by structr.

the class EMailValidator method isValid.

@Override
public boolean isValid(final NodeInterface node, final ErrorBuffer errorBuffer) {
    final Class type = node.getClass();
    final PropertyKey<String> eMail = StructrApp.key(type, "eMail");
    boolean valid = true;
    valid &= ValidationHelper.isValidUniqueProperty(node, eMail, errorBuffer);
    final String _eMail = (String) node.getProperty(eMail);
    if (_eMail != null) {
        // with user names.
        if (!_eMail.contains("@")) {
            valid = false;
            errorBuffer.add(new SemanticErrorToken(type.getSimpleName(), eMail, "must_contain_at_character", _eMail));
        }
    }
    return valid;
}
Also used : SemanticErrorToken(org.structr.common.error.SemanticErrorToken)

Example 2 with SemanticErrorToken

use of org.structr.common.error.SemanticErrorToken in project structr by structr.

the class User method onCreateAndModify.

// ----- public static methods -----
public static void onCreateAndModify(final User user, final SecurityContext securityContext) throws FrameworkException {
    final PropertyKey skipSecurityRels = StructrApp.key(User.class, "skipSecurityRelationships");
    if (user.getProperty(skipSecurityRels).equals(Boolean.TRUE) && !user.isAdmin()) {
        throw new FrameworkException(422, "", new SemanticErrorToken(user.getClass().getSimpleName(), skipSecurityRels, "can_only_be_set_for_admin_accounts"));
    }
    if (Settings.FilesystemEnabled.getValue()) {
        final PropertyKey<Folder> homeFolderKey = StructrApp.key(Folder.class, "homeFolderOfUser");
        final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
        // use superuser context here
        final SecurityContext storedContext = user.getSecurityContext();
        try {
            user.setSecurityContext(SecurityContext.getSuperUserInstance());
            Folder homeDir = user.getHomeDirectory();
            if (homeDir == null) {
                // create home directory
                final App app = StructrApp.getInstance();
                Folder homeFolder = app.nodeQuery(Folder.class).and(Folder.name, "home").and(parentKey, null).getFirst();
                if (homeFolder == null) {
                    homeFolder = app.create(Folder.class, new NodeAttribute(Folder.name, "home"), new NodeAttribute(Folder.owner, null), new NodeAttribute(Folder.visibleToAuthenticatedUsers, true));
                }
                app.create(Folder.class, new NodeAttribute(Folder.name, user.getUuid()), new NodeAttribute(Folder.owner, user), new NodeAttribute(Folder.visibleToAuthenticatedUsers, true), new NodeAttribute(parentKey, homeFolder), new NodeAttribute(homeFolderKey, user));
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            // restore previous context
            user.setSecurityContext(storedContext);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) SemanticErrorToken(org.structr.common.error.SemanticErrorToken) FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

SemanticErrorToken (org.structr.common.error.SemanticErrorToken)2 SecurityContext (org.structr.common.SecurityContext)1 FrameworkException (org.structr.common.error.FrameworkException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 NodeAttribute (org.structr.core.graph.NodeAttribute)1 PropertyKey (org.structr.core.property.PropertyKey)1