Search in sources :

Example 1 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class MangoCustomMethodSecurityExpressionRoot method hasAllPermissions.

/**
 * Does the user have every one of the supplied permissions
 * @param permissions
 * @return
 */
public boolean hasAllPermissions(String... permissions) {
    User user = (User) this.getPrincipal();
    if (user.isAdmin())
        return true;
    Set<String> userPermissions = Permissions.explodePermissionGroups(user.getPermissions());
    // TODO Use Collections.disjoint?
    for (String permission : permissions) {
        if (!userPermissions.contains(permission))
            return false;
    }
    return true;
}
Also used : User(com.serotonin.m2m2.vo.User)

Example 2 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidSetPermission.

/**
 * Does a user have data point set permissions?
 * @param vo
 * @return
 */
public boolean hasDataPointXidSetPermission(String xid) {
    User user = (User) this.getPrincipal();
    DataPointVO vo = DataPointDao.instance.getByXid(xid);
    return (vo != null) && Permissions.hasDataPointSetPermission(user, vo);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User)

Example 3 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidReadPermission.

/**
 * Does a user have data point read permissions?
 * @param vo
 * @return
 */
public boolean hasDataPointXidReadPermission(String xid) {
    User user = (User) this.getPrincipal();
    DataPointVO vo = DataPointDao.instance.getByXid(xid);
    return (vo != null) && Permissions.hasDataPointReadPermission(user, vo);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User)

Example 4 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method jsonWrite.

@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
    super.jsonWrite(writer);
    writer.writeEntry("activeRecipients", activeRecipients);
    writer.writeEntry("sendEscalation", sendEscalation);
    if (sendEscalation) {
        writer.writeEntry("escalationDelayType", Common.TIME_PERIOD_CODES.getCode(escalationDelayType));
        writer.writeEntry("escalationDelay", escalationDelay);
        writer.writeEntry("escalationRecipients", escalationRecipients);
        writer.writeEntry("keepSendingEscalations", repeatEscalations);
    }
    writer.writeEntry("sendInactive", sendInactive);
    if (sendInactive) {
        writer.writeEntry("inactiveOverride", inactiveOverride);
        if (inactiveOverride)
            writer.writeEntry("inactiveRecipients", inactiveRecipients);
    }
    writer.writeEntry("includeSystemInformation", includeSystemInfo);
    writer.writeEntry("includePointValueCount", includePointValueCount);
    writer.writeEntry("includeLogfile", includeLogfile);
    writer.writeEntry("customTemplate", customTemplate);
    JsonArray context = new JsonArray();
    for (IntStringPair pnt : additionalContext) {
        DataPointVO dpvo = DataPointDao.instance.get(pnt.getKey());
        if (dpvo != null) {
            JsonObject point = new JsonObject();
            point.put("dataPointXid", dpvo.getXid());
            point.put("contextKey", pnt.getValue());
            context.add(point);
        }
    }
    writer.writeEntry("additionalContext", context);
    writer.writeEntry("script", script);
    if (scriptPermissions != null) {
        JsonObject permissions = new JsonObject();
        permissions.put(ScriptPermissions.DATA_SOURCE, scriptPermissions.getDataSourcePermissions());
        permissions.put(ScriptPermissions.DATA_POINT_READ, scriptPermissions.getDataPointReadPermissions());
        permissions.put(ScriptPermissions.DATA_POINT_SET, scriptPermissions.getDataPointSetPermissions());
        writer.writeEntry("scriptPermissions", permissions);
    } else {
        writer.writeEntry("scriptPermissions", null);
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IntStringPair(com.serotonin.db.pair.IntStringPair) JsonObject(com.serotonin.json.type.JsonObject)

Example 5 with Permissions

use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method jsonRead.

@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String text = null;
    TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
    JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
    if (jsonActiveRecipients != null)
        activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
    JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
    if (b != null)
        sendEscalation = b.booleanValue();
    if (sendEscalation) {
        text = jsonObject.getString("escalationDelayType");
        if (text != null) {
            escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
            if (escalationDelayType == -1)
                throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
        }
        Integer i = jsonObject.getInt("escalationDelay", 1);
        if (i != null)
            escalationDelay = i;
        JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
        if (jsonEscalationRecipients != null)
            escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
        b = jsonObject.getJsonBoolean("keepSendingEscalations");
        if (b != null)
            repeatEscalations = b.booleanValue();
    }
    b = jsonObject.getJsonBoolean("sendInactive");
    if (b != null)
        sendInactive = b.booleanValue();
    if (sendInactive) {
        b = jsonObject.getJsonBoolean("inactiveOverride");
        if (b != null)
            inactiveOverride = b.booleanValue();
        if (inactiveOverride) {
            JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
            if (jsonInactiveRecipients != null)
                inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
        }
    }
    b = jsonObject.getJsonBoolean("includeSystemInformation");
    if (b != null)
        includeSystemInfo = b.booleanValue();
    includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
    b = jsonObject.getJsonBoolean("includeLogfile");
    if (b != null)
        includeSystemInfo = b.booleanValue();
    customTemplate = jsonObject.getString("customTemplate");
    JsonArray context = jsonObject.getJsonArray("additionalContext");
    if (context != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (JsonValue jv : context) {
            JsonObject jo = jv.toJsonObject();
            String dataPointXid = jo.getString("dataPointXid");
            if (dataPointXid == null)
                throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
            DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
            if (dpvo == null)
                throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
            String contextKey = jo.getString("contextKey");
            if (contextKey == null)
                throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
            additionalContext.add(new IntStringPair(dpvo.getId(), contextKey));
        }
        this.additionalContext = additionalContext;
    } else
        this.additionalContext = new ArrayList<>();
    script = jsonObject.getString("script");
    JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
    ScriptPermissions scriptPermissions = new ScriptPermissions();
    if (permissions != null) {
        String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
        if (perm != null)
            scriptPermissions.setDataSourcePermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
        if (perm != null)
            scriptPermissions.setDataPointReadPermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
        if (perm != null)
            scriptPermissions.setDataPointSetPermissions(perm);
    }
    this.scriptPermissions = scriptPermissions;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions) TypeDefinition(com.serotonin.json.util.TypeDefinition) JsonArray(com.serotonin.json.type.JsonArray) ArrayList(java.util.ArrayList) List(java.util.List) JsonBoolean(com.serotonin.json.type.JsonBoolean)

Aggregations

User (com.serotonin.m2m2.vo.User)61 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)43 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)40 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)36 ArrayList (java.util.ArrayList)27 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)20 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)17 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)16 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)15 HashMap (java.util.HashMap)15 List (java.util.List)14 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)10 ASTNode (net.jazdw.rql.parser.ASTNode)10 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)9 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)8 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)8 URI (java.net.URI)8 Map (java.util.Map)8 ResponseEntity (org.springframework.http.ResponseEntity)7