本文最后一次修改日期:2013-05-11
import java.security.Principal;
import java.util.Set;
import javax.naming.Context;
import javax.security.auth.Subject;
import weblogic.jndi.Environment;
import weblogic.security.Security;
import weblogic.security.principal.WLSGroupImpl;
import weblogic.security.principal.WLSUserImpl;
public class WebLogicSecurityUtils {
public static void main(String[] args) {
try {
Environment env = new Environment();
env.setProviderUrl("t3://localhost:7001");
env.setSecurityPrincipal("john");
env.setSecurityCredentials("welcome1");
Context ctx = env.getInitialContext();
Subject subject = Security.getCurrentSubject();
Set
for (Principal principal : allPrincipals) {
if (principal instanceof WLSGroupImpl) {
System.out.println("Group: " + principal.getName());
}
if (principal instanceof WLSUserImpl) {
System.out.println("User: " + principal.getName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
输出如下:
User: john
Group: Administrators
Group: employees
说明:这里我把用户john加在了两个组中:Administrator和employees。
参考文献:
1. http://blog.whitehorses.nl/2010/01/29/weblogic-web-application-container-security-part-1/
没有评论:
发表评论