List all the user in weblogic by java

≡放荡痞女 提交于 2019-12-06 10:37:38

问题


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?


回答1:


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();
  }
  }
}

EDIT


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.

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

The key settings are:

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


来源:https://stackoverflow.com/questions/24650838/list-all-the-user-in-weblogic-by-java

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