0

我想删除JasperReports Server存储库的文件夹之一。

我正在使用JR Serverrepository.deleteFolder(string URI)的 API 。但是,在删除该文件夹时,我得到“拒绝访问”,尽管我已经通过下面的方式授予了该文件夹的管理员权限。我还手动创建了一个 securitycontext 对象,因为这是部署我的应用程序时调用的代码

public void enableRoleAdministrator(ExecutionContext ctx, String userName,
        String folderName) {
    try {
        List ctxAttrib = ctx.getAttributes();
        if (ctxAttrib != null) {

            ctxAttrib.add(ObjectPermissionService.PRIVILEGED_OPERATION);
        } else {
            ctxAttrib = new ArrayList<String>();
            ctxAttrib.add(ObjectPermissionService.PRIVILEGED_OPERATION);

        }
        ctx.setAttributes(ctxAttrib);

        ObjectPermission userPermission = objectPermissionService
                .newObjectPermission(null);
        User user = profileAttributeService.getUserAuthorityService()
                .getUser(ctx, userName);
        userPermission.setURI("repo:/" + folderName);
        System.out.println("The URI is "+userPermission.getURI());
        userPermission.setPermissionRecipient(user);
        System.out.println("The userPermission is "+userPermission.getPermissionRecipient().toString());
        System.out.println("The user is "+user);
        userPermission.setPermissionMask(ADMINISTRATION);
        objectPermissionService.putObjectPermission(ctx, userPermission);
        System.out.println("Before calling delete Folder");
        repository.deleteFolder(ctx, folderName);

        System.out.println("After calling delete Folder");

    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception occurred" + ex.getMessage());
        System.out.println("Exception while deletingnnn forlder "+ex.getMessage());
        ex.printStackTrace();

    }
}
4

0 回答 0