简体   繁体   English

不推荐使用PDPrincipal.implies,备用类的暗含方法需要Subject

[英]PDPrincipal.implies deprecated, alternate class's implies method requires a Subject

I have the following running code to determine if a user can edit Object Namespace 我有以下运行代码来确定用户是否可以编辑对象命名空间

com.tivoli.mts.PDPrincipal whoIsit = new PDPrincipal(userId,configURL);
    com.tivoli.mts.PDPermission whatTheyWant = new PDPermission(objectSpaceName,GMTConstants.tamPermissions);

    boolean haveAccess = whoIsit.implies(whatTheyWant);

The problem is that the implies method from com.tivoli.mts.PDPrincipal class has been deprecated. 问题是com.tivoli.mts.PDPrincipal类的implies方法已被弃用。

This has been replaced by com.tivoli.pd.jazn.PDPrincipal.implies(javax.security.auth.Subject subject) 替换为com.tivoli.pd.jazn.PDPrincipal.implies(javax.security.auth.Subject主题)

Question is how do i construct this Subject object. 问题是如何构造此Subject对象。 Secondly, can i continue to use the deprecated clas and method? 其次,我可以继续使用已过时的分类和方法吗?

I was able to work out a solution for this hence sharing it here so that anyone else facing the same issue can use this code. 我能够为此解决一个问题,因此可以在这里共享它,以便其他面临相同问题的人都可以使用此代码。

I found that the new com.tivoli.pd.jazn.PDPermission class has a method implies which takes in a PdAuthorization context and a com.tivoli.pd.jazn.PDPrincipal object which does the same authorization checks that the previous class com.tivoli.mts.PDPrincipal use to do. 我发现新的com.tivoli.pd.jazn.PDPermission类具有一个隐含方法,该方法隐含PdAuthorization上下文和一个com.tivoli.pd.jazn.PDPrincipal对象,该对象执行与上一类com.tivoli相同的授权检查.mts.PDPrincipal使用来做。

Mentioned below is how the same authorization can be done. 下面提到的是如何完成相同的授权。 With this code you need not implement the JAAS code. 使用此代码,您无需实现JAAS代码。

First construct the PdAuthorizationContext as shown below. 首先构造PdAuthorizationContext,如下所示。 Make sure to define a static PdAuthorizationContext object so that it can be reused untill you close it. 确保定义一个静态PdAuthorizationContext对象,以便在您将其关闭之前可以重复使用它。 Constructing PDAuthorizationContext for every authorization check is resource intensive and not recommended. 为每个授权检查构造PDAuthorizationContext会占用大量资源,因此不建议这样做。 close the context at the end of your logic 在逻辑结尾处关闭上下文

URL configURL = new URL("file:" + String locationToTamConfigFile);
   PDAuthorizationContext pdAuthCtx =  new PDAuthorizationContext(configURL);

Next Construct the new PDPrincipal and the PdPermission objects as shown below and call the implies method 下一步构造新的PDPrincipal和PdPermission对象,如下所示,并调用implies方法

com.tivoli.pd.jazn.PDPrincipal pdPrincipal = new        com.tivoli.pd.jazn.PDPrincipal(pdAuthCtx,userId);
com.tivoli.pd.jazn.PDPermission pdPermission = new    com.tivoli.pd.jazn.PDPermission(objectSpaceName,"TbvA");
boolean newimpliesTry = pdPermission.implies(pdAuthCtx,pdPrincipal);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM