Is it possible to use SharedSecrets across Java modules?

主宰稳场 提交于 2020-05-15 04:10:41

问题


Given:

  • Modules A and B, where B imports A.
  • Module A exports external.class1. It defines but does not export external.class1.secretProvider, internal.SharedSecrets and internal.class2 (more on these below).
  • Module A uses the SharedSecrets mechanism to grant external.class1 access to private methods in internal.class2 using external.class1.secretProvider.

I wish to grant external.class3 (defined in Module B) access to private methods in internal.class2 but seeing as internal.SharedSecrets and external.class1.secretProvider are not exported by A I have no way of doing so.

Is there a way for B to access to A's secrets without exporting them for the whole world to see?


回答1:


Is there a way for B to access to A's secrets without exporting them for the whole world to see?

If I am not getting the question wrong, you can use qualified exports to make sure you export those packages just to a specific (list of) module. You can do so as :

module A {
    exports external.class1.secretProvider to B;
    exports internal.SharedSecrets to B;
    // ... rest of your declarations
}


来源:https://stackoverflow.com/questions/53653132/is-it-possible-to-use-sharedsecrets-across-java-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!