加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 在WildFly中使用自定义授权管理器

发布时间:2020-12-15 02:16:46 所属栏目:Java 来源:网络整理
导读:我已经成功使用自定义登录模块.现在我尝试使用以下代码告诉WildFly使用我自己的自定义授权管理器: 的jboss-web.xml中: ?xml version="1.0" encoding="UTF-8"?jboss-web security-domainCustomSecurityDomain/security-domain/jboss-web standalone.xml: .
我已经成功使用自定义登录模块.现在我尝试使用以下代码告诉WildFly使用我自己的自定义授权管理器:

的jboss-web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>CustomSecurityDomain</security-domain>
</jboss-web>

standalone.xml:

...
        <subsystem xmlns="urn:jboss:domain:security:1.2">
            <security-domains>
                ...
                <security-domain name="CustomSecurityDomain" cache-type="default">
                    <authentication>
                        <login-module code="my.CustomLoginModule" flag="required">
                            <module-option name="usersProperties" value="user.properties"/>
                            <module-option name="rolesProperties" value="roles.properties"/>
                        </login-module>
                    </authentication>
                    <authorization>
                        <policy-module code="my.CustomAuthorizationManager" flag="required"/>
                    </authorization>
                </security-domain>
            </security-domains>
        </subsystem>
        ...

CustomAuthorizationManager.java:

package my;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import io.undertow.security.idm.Account;
import io.undertow.servlet.api.AuthorizationManager;
import io.undertow.servlet.api.Deployment;
import io.undertow.servlet.api.ServletInfo;
import io.undertow.servlet.api.SingleConstraintMatch;
import io.undertow.servlet.api.TransportGuaranteeType;

public class CustomAuthorizationManager implements AuthorizationManager {

    @Override
    public boolean canAccessResource(List<SingleConstraintMatch> arg0,Account arg1,ServletInfo arg2,HttpServletRequest arg3,Deployment arg4) {
        // do something
        return false;
    }

    @Override
    public boolean isUserInRole(String arg0,Deployment arg4) {
        // do something
        return false;
    }

    @Override
    public TransportGuaranteeType transportGuarantee(TransportGuaranteeType arg0,TransportGuaranteeType arg1,HttpServletRequest arg2) {
        // do something
        return null;
    }

}

通过使用调试器并将断点设置到我自己的CustomAuthorizationManager和默认的io.undertow.servlet.core.DefaultAuthorizationManager实现,我可以看到它使用默认值而不是我的自定义实现.似乎WildFly忽略了standalone.xml中的配置.
将WildFly调试级别设置为TRACE表明我的CustomAuthorizationManager已正确部署.我尝试使用WildFly 9和10,两者的行为方式相同.

有谁知道这是一个错误还是错过了配置步骤?

解决方法

尝试安全管理元素,如下所述: https://docs.jboss.org/author/display/WFLY10/Security+subsystem+configuration

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读