gpt4 book ai didi

java - Spring 安全和 Struts 2

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:06 26 4
gpt4 key购买 nike

我有一个带有 @Secured({"ROLE_ADMIN"}) 的 struts2 Action 以保护执行方法。在 execute 方法中,我将消息分配给操作的成员变量,然后返回 SUCCESS 并在 jsp 页面上结束。在页面上,我使用 <sproperty> 检索 actions 成员变量.

private String greeting;

public String execute() throws Exception {
this.greeting="Hello";
return SUCCESS;
}

// getters and setters for greeting
...

<s:property value="greeting" />

问题是当存在安全注释时,jsp 不显示任何成员变量,但当 @Secured 时被删除后,整个事情都会正常运行并显示设置到成员变量中的消息。

看起来实际的安全性工作正常,但是当通过注释启用时,成员变量(或者可能是操作的实例)没有进入值堆栈。

我看不到任何错误消息。

最佳答案

你必须确保在 <s:property value="greeting" /> 之前执行后,您在 SecurityContextHolder.getContext() 中将“ROLE_ADMIN”作为授权权限存在.

此外,如果您使用存储安全上下文的默认“线程本地”策略,请确保授予的权限已正确存储在每个请求线程中。例如,如果您在 http session 中存储有关用户凭据的信息,则需要 HttpSessionContextIntegrationFilter设置。

作为最后的手段,如果有可能,您可以在您正在使用的 Spring Security Interceptor 中进行逐步调试 session ,并检查问题所在。

关于java - Spring 安全和 Struts 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1612485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com