用java列出weblogic中的所有用户 [英] List all the user in weblogic by java

查看:114
本文介绍了用java列出weblogic中的所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在java中列出所有weblogic用户?
例如,安全领域有5个用户,我希望得到所有这些用户。我该怎么办?

Does anyone know how to list all the weblogic users in java? For instance, there is 5 users in security realm, and I want to get all of them. How do I do?

推荐答案

这很简单。为了将来参考,如果你想在谷歌搜索中使用 JMX 查找我如何使用weblogic和Java进行X ...之类的操作。以下是 weblogic奇迹。请注意,您需要在代码中更改您的URL和用户/密码:

It's pretty easy. For future reference, if you want to look up something like "how do I do X with weblogic and Java..." use JMX in your google search. Here is an example from weblogic wonders. Note you will need to change your URL and user/password in the code:

import javax.naming.*;
import javax.management.MBeanInfo;
import weblogic.jndi.Environment;
import weblogic.management.runtime.ServerRuntimeMBean;
import weblogic.security.providers.authentication.DefaultAuthenticatorMBean;
import weblogic.management.security.authentication.UserReaderMBean;
import weblogic.management.security.authentication.GroupReaderMBean;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicMBean;
import weblogic.management.tools.Info;
import weblogic.management.Helper;
import weblogic.management.security.authentication.*;

public class ListUsersAndGroups
{
  public static void main(String[] args)
  {

  MBeanHome home = null;
  try
  {

    Environment env = new Environment();
    env.setProviderUrl("t3://localhost:7001?);
    env.setSecurityPrincipal("weblogic");
    env.setSecurityCredentials("weblogic");
    Context ctx = env.getInitialContext();

    home = (MBeanHome)ctx.lookup("weblogic.management.adminhome");

    weblogic.management.security.RealmMBean rmBean = 
   home.getActiveDomain().getSecurityConfiguration().getDefaultRealm();

    AuthenticationProviderMBean[] authenticationBeans = 
    rmBean.getAuthenticationProviders();
    DefaultAuthenticatorMBean defaultAuthenticationMBean = 
    (DefaultAuthenticatorMBean)authenticationBeans[0];
    UserReaderMBean userReaderMBean = 
    (UserReaderMBean)defaultAuthenticationMBean;

    String userCurName = userReaderMBean.listUsers("*", 100);

    while (userReaderMBean.haveCurrent(userCurName) )
    {
      String user = userReaderMBean.getCurrentName(userCurName);
      System.out.println("\n User: " + user);
      userReaderMBean.advance(userCurName);
    }

  }
  catch (Exception e)
  {
    e.printStackTrace();
  }
  }
}

编辑

没有任何方法可以知道用户/密码来查找用户。如果这听起来像是一个更好的选择,你也可以通过WLST脚本来完成。请参阅此处示例。

There isn't really any way around have to know the user/password to look up the users. You can do it via WLST scripting as well if that sounds like a better option. See an example here.

最后但并非最不重要的是,您可以在嵌入式ldap for Weblogic上设置匿名绑定,以允许匿名查找(通常不建议用于生产)。此示例显示如何使用外部客户端执行此操作: Weblogic w / External Ldap Client

Last but not least, you could set anonymous bind on the embedded ldap for Weblogic to allow anonymous lookups (which is generally not recommended for production). This sample shows how to do it with an external client: Weblogic w/External Ldap Client

关键设置为:

Your Domain -> Security -> Embedded LDAP
Change the (default generated) password (for example: weblogic)
Enable "Anonymous Bind Allowed" 

这篇关于用java列出weblogic中的所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆