【问题标题】:How to create custom pages in Broadleaf Admin如何在 Broadleaf Admin 中创建自定义页面
【发布时间】:2019-10-28 19:02:46
【问题描述】:

我试图在我的 broadleaf e-commerce 管理员端创建自定义页面。我关注了这个tutorial。但是当我尝试访问该页面时,我收到了这个奇怪的错误。 。这是我的控制器的代码:

package com.community.admin.controller;

import org.broadleafcommerce.openadmin.web.controller.AdminAbstractController;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/" + ThemeController.SECTION_KEY)
@Secured("PERMISSION_OTHER_DEFAULT")
public class ThemeController extends AdminAbstractController {

    protected static final String SECTION_KEY = "test";

    @RequestMapping(value = "", method = RequestMethod.GET)
    public String test(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        // This is expected by the modules/emptyContainer template, this is a custom template that gets included into the body
        model.addAttribute("customView", "views/test");

        // ensure navigation gets set up correctly
        setModelAttributes(model, SECTION_KEY);

        // gets the scaffolding set up to display the template from the customView attribute above
        return "modules/emptyContainer";
    }

}

由于没有教程中所述的 Web-INF 文件夹,所以我将我的 html 文件添加到 Resources > open_admin_styles > templates > views 文件夹中,该文件夹中存在其他 html 页面。任何帮助将不胜感激,谢谢

P.S:我收到了AccessDeniedException。我执行了以下权限查询:

INSERT INTO `blc_admin_module` (`ADMIN_MODULE_ID`, `DISPLAY_ORDER`, `ICON`, `MODULE_KEY`, `NAME`) VALUES (1, 7, 'icon-barcode', 'MyCustomModule', 'My Custom Module');
INSERT INTO `blc_admin_section` (`ADMIN_SECTION_ID`, `DISPLAY_ORDER`, `NAME`, `SECTION_KEY`, `URL`, `ADMIN_MODULE_ID`) VALUES (1, 1000, 'My Custom Section', 'MyCustomSection', '/test', 1);
INSERT INTO `blc_admin_sec_perm_xref` (`ADMIN_SECTION_ID`, `ADMIN_PERMISSION_ID`) VALUES (1, -1);

编辑

删除安全注释可以解决问题,不管我是否按照文档中的说明在 db 中添加了所有权限。

【问题讨论】:

    标签: broadleaf-commerce


    【解决方案1】:

    以上答案解决了安全问题。但我在 6.1.5-GA 版本的管理员中也找不到 Web-INF 文件夹和 Resources > open_admin_styles > templates > views 文件夹。

    然后我在上面添加test.html文件

    admin > src > main > resources > community-demo-style.templates.admin

    文件夹。

    并且还在MyController 类中将/test.html 提供给model.addAtrribute(),例如model.addAttribute("customView", "/test.html");

    对我来说很好用。

    MyController image

    【讨论】:

      【解决方案2】:

      Spring Framework Security 使用“ROLE_”前缀,所以你不能使用@Secured("PERMISSION_OTHER_DEFAULT"),因为 RoleVoter 不会处理它。 您必须更改所有 Broadleaf 权限名称,添加“ROLE_”前缀才能使其生效。

      在这种情况下,您必须将数据库中的“PERMISSION_OTHER_DEFAULT”更改为“ROLE_PERMISSION_OTHER_DEFAULT”并在控制器中用作:

      @Controller
      @RequestMapping("/" + ThemeController.SECTION_KEY)
      @Secured("ROLE_PERMISSION_OTHER_DEFAULT")
      public class ThemeController extends AdminAbstractController {
         //something
      }
      

      对其他权限执行相同操作。

      这里有一些信息:https://docs.spring.io/spring-security/site/docs/4.2.13.BUILD-SNAPSHOT/apidocs/org/springframework/security/access/vote/RoleVoter.html

      【讨论】:

        猜你喜欢
        • 2012-04-20
        • 1970-01-01
        • 2019-01-07
        • 2012-02-12
        • 2013-10-04
        • 1970-01-01
        • 2019-09-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多