使用spring security保护xhtml站点

lb3vh1jj  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(204)

如何使用spring security保护xhtml站点?
这意味着,如果用户具有特定角色,则必须加载页面;否则,它会显示错误代码:403。稍后,我可以在web.xml中对403作出React,并将其转发到主页。
作为一个技术堆栈,我使用KeyClope和spring security。该应用程序的特点是我们应该管理应用程序中的许多角色。可以在运行时更改角色。假设我总是可以从会话中获取所选角色,我希望显示或拒绝某些角色的某些页面。现在,我正在寻找一种可能性(类似的或类似的:
@预授权(“hasrole(user.getselectedrole())”)
伪示例:
pagecontroller.java

@RequestScoped
@PreAuthorize ("hasRole (user.getSelectedRole ())")
public class SecureController {
// do something
}

page.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/WEB-INF/template.xhtml">

    <ui:define name="title"> Page</ui:define>
    <ui:define name="content">
        <div class="card card-w-title">
            <h:form>
                <div class="card-title"> <h2>#{msg['page.header']}</h2> </div>
            </h:form>
        </div>
    </ui:define>
</ui:composition>

securityconfig.java

protected void configure(HttpSecurity http) throws Exception {

        http
            .csrf().disable()

            .authorizeRequests()

            // public available resources for everyone
            .antMatchers("/css/",
                    "/resource/**",
                    "/javax.faces.resource/**", // ?!?
                    "/index.html").permitAll()
            ...

            .antMatchers("/tsv/secure/secure.xhtml")
            .hasRole('ROLE_XYZ')

            .anyRequest()
            .authenticated();
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题