2016-03-14 37 views
0

找回密码,我在部署在WebLogic 12.2.1 Web服务下面的代码。它将从WebLogic配置中检索密钥库文件名和密码。无法从WebLogic配置

InitialContext ic = new InitialContext(); 
    MBeanServer server = (MBeanServer) ic.lookup("java:comp/env/jmx/runtime"); 
    ObjectName runtime = new ObjectName("com.bea:Name=MLMAppSrv01,Type=Server"); 
    Object keyStoreFileName = server.getAttribute(runtime, "CustomIdentityKeyStoreFileName"); 
    Object keyStorePassPhrase = server.getAttribute(runtime, "CustomIdentityKeyStorePassPhrase"); 

它能够获取密钥库文件名,但是当它试图找回密码,以下异常被抛出。

[Management:141302]Access not allowed for Subject: principals=[], on resource Server, action: read, target CustomIdentityKeyStorePassPhrase. 

在域的安全性下,我已经启用了“启用清除文本凭据访问”。

还有什么可能是错误的?

在此先感谢。

回答

0

您没有传递任何用户名在你的代码。使用weblogic用户或其他管理员用户,您应该检索密码。否则,它不会允许您访问密码。

如果你想使用一些其他的用户比的WebLogic然后确保你的用户添加到管理员组。

+0

在WebLogic服务器启动为使用具有管理员权限的Windows登录ID的服务(可以称之为ID “X”) 。要登录WebLogic控制台,我使用了一个ID(我们称这个ID为“Y”)。是我需要在我的代码“Y”中传递的用户名,是否可以登录WebLogic控制台的相同ID?我如何在我的代码中这样做? – user3573403

0

您可以通过下面的示例代码给出的凭据。

Hashtable properties = new Hashtable(); 
    properties.put(Context.INITIAL_CONTEXT_FACTORY, 
        "weblogic.jndi.WLInitialContextFactory"); 
    // NOTE: The port number of the server is provided in the next line, 
    //  followed by the userid and password on the next two lines. 
    properties.put(Context.PROVIDER_URL, "t3://localhost:9001"); 
    properties.put(Context.SECURITY_PRINCIPAL, "weblogic"); 
    properties.put(Context.SECURITY_CREDENTIALS, "welcome1"); 
    try { 
     ctx = new InitialContext(properties); 
    } catch (NamingException ne) { 
     ne.printStackTrace(System.err); 
     System.exit(0); 
    } 
+0

我需要访问我的代码中的密钥库,所以我需要获取密码。我没有在密码中硬编码密码,而是想到从Weblogic配置中检索密码。现在,您的建议是代码中对代码中的weblogic密码进行硬编码。它似乎并没有解决我没有对密码进行硬编码的问题。 – user3573403

+0

你想要检索密钥库或Weblogic域的密码吗? –

+0

我正在尝试使用代码检索密钥存储区密码。但为此,我需要现在检索weblogic密码。密码中不允许硬编码。您正在对代码中的weblogic密码进行硬编码。 – user3573403

0

我认为您没有通过身份验证,因此无法访问受限制的资源。在您的类中添加注释@RunAs(“WEBLOGIC”)并将其配置到WEB-INF/weblogic-ejb-jar.xml中(其中WEBLOGIC是Weblogic控制台中具有管理员权限的用户的名称,默认的管理员帐户甚至名为weblogic)

你的类应该是这样的:在weblogic-ejb-jar.xml中的

@Stateless 
@RunAs("WEBLOGIC") 
public class SomeService { 
// ... 
} 

内容

<?xml version="1.0" encoding="UTF-8"?> 
<weblogic-ejb-jar> 
    <run-as-role-assignment> 
    <role-name>WEBLOGIC</role-name> 
    <run-as-principal-name>weblogic</run-as-principal-name> 
    </run-as-role-assignment> 
</weblogic-ejb-jar> 
+0

如果我的weblogic用户名是“wlsadm”,那我该怎么做?我应该为@RunAs指定“wlsadm”还是WEBLOGIC?那么weblogic-ejb-jar.xml呢? – user3573403

+0

只需用wlsadm替换“weblogic”即可(所有事件都易于阅读)。 weblogic-ejb-jar.xml应位于您的WEB-INF文件夹中,如果不创建它的话。应用程序只需要知道要使用哪个角色。既然你使用WebService,你有一个Web应用程序,对吧? – Slettal

+0

我终于今天尝试了您的解决方案,但它仍然无法正常工作。我的weblogic管理标识是“wlsysad”。我建议您将@RunAs(“wlsysad”)放在Web服务类的顶部。然后我按照您的建议使用内容创建了WEB-INF \ weblogic-ejb-jar.xml。对于,我将这两个值都设置为“wlsysad”。 – user3573403

0

我有一个类似CA se,我的泽西岛代码需要通过编程方式在WLS中从密钥库中获取密钥。不需要EJB设置。您只需要正确定义web.xml和weblogic.xml。

的web.xml:

<servlet> 
    <servlet-name>{jersey webservice class}</servlet-name> 
    <run-as> 
     <role-name>admRole</role-name> 
    </run-as>   
</servlet> 

<security-role> 
    <role-name>admRole</role-name> 
</security-role> 

的weblogic.xml:

<run-as-role-assignment> 
    <role-name>admRole</role-name> 
    <run-as-principal-name>wlsadm</run-as-principal-name> 
</run-as-role-assignment>