Search in sources :

Example 6 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class DefaultPermissionValuesConfig method parseConfigFile.

protected void parseConfigFile(String fileName) {
    String fileContent = resources.getResourceAsString(fileName);
    if (!Strings.isNullOrEmpty(fileContent)) {
        Document document = Dom4j.readDocument(fileContent);
        List<Element> permissionElements = Dom4j.elements(document.getRootElement(), "permission");
        for (Element element : permissionElements) {
            String target = element.attributeValue("target");
            Integer value = Integer.valueOf(element.attributeValue("value"));
            Integer type = Integer.valueOf(element.attributeValue("type"));
            Permission permission = metadata.create(Permission.class);
            permission.setTarget(target);
            permission.setType(PermissionType.fromId(type));
            permission.setValue(value);
            permissionValues.put(target, permission);
        }
    } else {
        log.error("File {} not found", fileName);
    }
}
Also used : Element(org.dom4j.Element) Permission(com.haulmont.cuba.security.entity.Permission) Document(org.dom4j.Document)

Example 7 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class UpdateDetachedTest method testRollback.

@Test
public void testRollback() {
    Permission p = null;
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        p.setTarget("newTarget");
        em = cont.persistence().getEntityManager();
        p = em.merge(p);
        throwException();
        tx.commit();
    } catch (RuntimeException e) {
    // ok
    } finally {
        tx.end();
        assertNotNull(p);
    // assertNull(((PersistenceCapable) p).pcGetDetachedState());
    }
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission) Test(org.junit.Test)

Example 8 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class UpdateDetachedTest method testDataService.

@Test
public void testDataService() throws Exception {
    Permission p;
    DataService ds = AppBeans.get(DataService.NAME);
    LoadContext<Permission> ctx = new LoadContext<>(Permission.class);
    ctx.setId(permissionId);
    ctx.setView(new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name")));
    p = ds.load(ctx);
    assertNotNull(p);
    p.setTarget("newTarget");
    CommitContext commitCtx = new CommitContext(Collections.singleton(p));
    Set<Entity> entities = ds.commit(commitCtx);
    Permission result = null;
    for (Entity entity : entities) {
        if (entity.equals(p))
            result = (Permission) entity;
    }
    result = reserialize(result);
    assertTrue(PersistenceHelper.isDetached(result));
    assertNotNull(result.getRole());
    assertTrue(PersistenceHelper.isDetached(result.getRole()));
    assertTrue(PersistenceHelper.isLoaded(result, "role"));
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Entity(com.haulmont.cuba.core.entity.Entity) Permission(com.haulmont.cuba.security.entity.Permission) DataService(com.haulmont.cuba.core.app.DataService) Test(org.junit.Test)

Example 9 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class UpdateDetachedTest method test.

@Test
public void test() throws Exception {
    Permission p;
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        assertNotNull(p);
        p.setTarget("newTarget");
        em = cont.persistence().getEntityManager();
        p = em.merge(p);
        tx.commit();
    } finally {
        tx.end();
    }
    p = reserialize(p);
    assertTrue(PersistenceHelper.isDetached(p));
    assertNotNull(p.getRole());
    assertTrue(PersistenceHelper.isDetached(p.getRole()));
    assertTrue(PersistenceHelper.isLoaded(p, "role"));
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission) Test(org.junit.Test)

Example 10 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class SystemInfoWindow method generateInsert.

public void generateInsert() {
    scriptArea.setEditable(true);
    if (item instanceof Role) {
        View localView = metadata.getViewRepository().getView(Role.class, View.LOCAL);
        View roleView = new View(localView, Role.class, "role-export-view", true).addProperty("permissions", metadata.getViewRepository().getView(Permission.class, View.LOCAL));
        item = getDsContext().getDataSupplier().reload(item, roleView);
        StringBuilder result = new StringBuilder();
        result.append(sqlGenerationService.generateInsertScript(item)).append("\n");
        for (Permission permission : ((Role) item).getPermissions()) {
            result.append(sqlGenerationService.generateInsertScript(permission)).append("\n");
        }
        scriptArea.setValue(result.toString());
    } else {
        scriptArea.setValue(sqlGenerationService.generateInsertScript(item));
    }
    showScriptArea();
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Permission(com.haulmont.cuba.security.entity.Permission) View(com.haulmont.cuba.core.global.View)

Aggregations

Permission (com.haulmont.cuba.security.entity.Permission)15 Role (com.haulmont.cuba.security.entity.Role)4 PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)3 Test (org.junit.Test)3 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)2 UiPermissionVariant (com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 DataService (com.haulmont.cuba.core.app.DataService)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 View (com.haulmont.cuba.core.global.View)1 RestorablePermissionDatasource (com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource)1 AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)1 OperationPermissionTarget (com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)1 UiPermissionTarget (com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)1 PermissionValue (com.haulmont.cuba.gui.app.security.role.edit.PermissionValue)1 PermissionConfig (com.haulmont.cuba.gui.config.PermissionConfig)1