如何在Broadleaf Admin中创建自定义页面

问题描述 投票:2回答:1

我正在尝试在broadleaf e-commerce管理员端创建自定义页面。我遵循了此tutorial。但是,当我尝试访问页面时,出现此奇怪错误。 enter image description here。这是我的控制器的代码:

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文件夹,所以我在Resources > open_admin_styles > templates > views文件夹中添加了我的html文件,该文件夹中还存在其他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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.