【问题标题】:List all the user in weblogic by java通过java列出weblogic中的所有用户
【发布时间】:2014-07-09 10:10:03
【问题描述】:

有谁知道如何列出java中的所有weblogic用户? 例如,安全领域有 5 个用户,我想获取所有用户。我该怎么办?

【问题讨论】:

    标签: java weblogic jmx


    【解决方案1】:

    这很容易。以供将来参考,如果您想查找诸如“我如何使用 weblogic 和 Java 进行 X...”之类的内容,请在您的谷歌搜索中使用 JMX。这是来自weblogic wonders 的示例。请注意,您需要更改代码中的 URL 和用户/密码:

    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 脚本来完成。查看示例here

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

    关键设置是:

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

    【讨论】:

    • 是的,我们可以这样做。但是还有一个问题:您必须在代码中输入用户名和密码。我知道我们可以从 boot.properties 中读取这些信息,但是您还有其他方法吗?我不想过多使用 JMX。
    • 编辑了更多可能有用的信息
    • 我正在使用您提到的相同程序,但我在这一行“DefaultAuthenticatorMBean defaultAuthenticationMBean = (DefaultAuthenticatorMBean)authenticationBeans [ 0]; "
    猜你喜欢
    • 2011-02-24
    • 2020-07-25
    • 2020-03-26
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多