Search in sources :

Example 1 with ModelRolePermissionBatch

use of com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch in project liferay-imex by jpdacunha.

the class ImexPropertiesModelRolePermissionReaderImpl method getRolesBatchs.

/*
	 * (non-Javadoc)
	 * @see com.liferay.portal.permission.model.batch.reader.ModelRolePermissionReader#getRolesBatchs(java.lang.String)
	 */
public List<ModelRolePermissionBatch> getRolesBatchs(String batchId, Properties props) throws PortalException, SystemException {
    List<ModelRolePermissionBatch> liste = new ArrayList<ModelRolePermissionBatch>();
    if (props == null) {
        _log.warn("Missing required properties");
        return liste;
    }
    String[] roles = CollectionUtil.getArray(props.getProperty(ImExCorePropsKeys.PERMISSIONS_SUPPORTED_ROLES));
    if (roles != null && roles.length > 0) {
        List<String> rolesNames = Arrays.asList(roles);
        for (String roleName : rolesNames) {
            ModelRolePermissionBatch batch = readRoleBatch(batchId, roleName, props);
            if (ModelRolePermissionBatch.validate(batch)) {
                liste.add(batch);
            }
        }
    } else {
        _log.error("Invalid configuration : no roles are defined. Please check  [" + ImExCorePropsKeys.PERMISSIONS_SUPPORTED_ROLES + "] is correctly defined");
    }
    return liste;
}
Also used : ModelRolePermissionBatch(com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch) ArrayList(java.util.ArrayList)

Example 2 with ModelRolePermissionBatch

use of com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch in project liferay-imex by jpdacunha.

the class ImexModelPermissionSetterImpl method setPermissions.

public void setPermissions(Properties props, Bundle bundle, Resource resource) throws SystemException, PortalException {
    String batchId = bundle.getSymbolicName();
    boolean reinitOnset = reader.isReinitOnset(batchId, props);
    List<ModelRolePermissionBatch> roleBatchs = reader.getRolesBatchs(batchId, props);
    ModelPermissionBatch batch = new ModelPermissionBatch(resource, batchId, reinitOnset, roleBatchs);
    setPermissions(batch);
}
Also used : ModelPermissionBatch(com.liferay.imex.core.api.permission.model.ModelPermissionBatch) ModelRolePermissionBatch(com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch)

Example 3 with ModelRolePermissionBatch

use of com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch in project liferay-imex by jpdacunha.

the class ImexPropertiesModelRolePermissionReaderImpl method readRoleBatch.

/**
 * Lis dans le fichier de configuration le batch configuré pour un role. Null sinon
 * @param batchId
 * @param roleName
 * @return
 * @throws PortalException
 * @throws SystemException
 */
private static ModelRolePermissionBatch readRoleBatch(String batchId, String roleName, Properties properties) throws PortalException, SystemException {
    List<String> actions = null;
    ModelRolePermissionBatch batch = null;
    String key = buildRoleActionsKey(batchId, roleName);
    if (key != null) {
        String[] actionsArray = CollectionUtil.getArray((String) properties.get(key));
        if (actionsArray != null && actionsArray.length > 0) {
            actions = Arrays.asList(actionsArray);
            batch = new ModelRolePermissionBatch(roleName, actions);
        } else {
            _log.warn("No rule defined for role:[" + roleName + "], key:[" + key + "]");
        }
    }
    if (ModelRolePermissionBatch.validate(batch)) {
        return batch;
    }
    return null;
}
Also used : ModelRolePermissionBatch(com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch)

Example 4 with ModelRolePermissionBatch

use of com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch in project liferay-imex by jpdacunha.

the class ImexModelPermissionSetterImpl method setPermissions.

/**
 * Traitement de positionnement des permissions
 * @param batch
 * @param logger
 * @throws PortalException
 * @throws SystemException
 */
public void setPermissions(ModelPermissionBatch batch) throws PortalException, SystemException {
    if (ModelPermissionBatch.validate(batch)) {
        reportService.getStartMessage(_log, "Setting permissions");
        Resource resource = batch.getResource();
        List<ModelRolePermissionBatch> roleActions = batch.getBatchs();
        long companyId = resource.getCompanyId();
        String resourceName = resource.getName();
        String resourcePrimKey = resource.getPrimKey();
        boolean reInitOnSet = batch.isReInitOnSet();
        reportService.getPropertyMessage(_log, "Selected batch", batch.getBatchId());
        reportService.getPropertyMessage(_log, "Permissions reinitialisation", reInitOnSet + "");
        reportService.getPropertyMessage(_log, "Resource Name", resourceName);
        reportService.getPropertyMessage(_log, "Resource Primary Key", resourcePrimKey);
        if (roleActions != null && roleActions.size() > 0) {
            // Deleting previous setted permissions
            if (reInitOnSet) {
                resetPermissions(companyId, resource);
            }
            // Setting permissions on resource
            for (ModelRolePermissionBatch roleBatch : roleActions) {
                setPermissionsRole(roleBatch, resource);
            }
        } else {
            reportService.getMessage(_log, "No permissions to set");
        }
        reportService.getEndMessage(_log, "Setting permissions");
    } else {
        reportService.getError(_log, "Invalid parameter", "Unable to execute invalid batch");
    }
}
Also used : ModelRolePermissionBatch(com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch) Resource(com.liferay.portal.kernel.model.Resource)

Aggregations

ModelRolePermissionBatch (com.liferay.imex.core.api.permission.model.ModelRolePermissionBatch)4 ModelPermissionBatch (com.liferay.imex.core.api.permission.model.ModelPermissionBatch)1 Resource (com.liferay.portal.kernel.model.Resource)1 ArrayList (java.util.ArrayList)1