zoukankan      html  css  js  c++  java
  • JAAS LOGIN IN WEBLOGIC SERVER--reference

    The Java Authentication and Authorization Service (JAAS) is a standard extension to the security in the J2SE Development Kit 5.0. JAAS provides the ability to enforce access controls based on user identity. JAAS is provided in WebLogic Server as an alternative to the JNDI authentication mechanism.

    WebLogic Server clients use the authentication portion of the standard JAAS only. The JAAS LoginContext provides support for the ordered execution of all configured authentication provider LoginModule instances and is responsible for the management of the completion status of each configured provider.

    //JAASLogin.java
    
    import javax.security.auth.Subject;
    import javax.security.auth.callback.*;
    import javax.security.auth.login.*;
    
    import weblogic.security.auth.callback.URLCallback;
    
    public class JAASLogin
    {
    private static final class ConfigInfo
    {
    static String USERID = “weblogic”;
    static String PASSWORD = “weblogic”;
    static String URL = “t3://10.10.71.79:7001?;
    static String JAAS_STRING = “other”;
    
    }
    
    public static void main(String[] args)
    {
    
    try{
    System.out.println(“Server is at ” + ConfigInfo.URL);
    System.out.println(“Userid: ” + ConfigInfo.USERID);
    System.out.println(“Password: ” + ConfigInfo.PASSWORD);
    LoginContext lc = new LoginContext(ConfigInfo.JAAS_STRING, new JAASLogin.CallbackHandler(ConfigInfo.USERID, ConfigInfo.PASSWORD, ConfigInfo.URL));
    System.out.println(“LoginContext:: “);
    lc.login();
    System.out.println(“lc.login():: “);
    Subject subject = lc.getSubject();
    System.out.println(“Subject: ” + subject);
    }
    catch(AccountExpiredException ae){
    
    ae.printStackTrace();
    }
    catch(CredentialExpiredException ce){
    
    ce.printStackTrace();
    }
    catch(FailedLoginException fe){
    
    fe.printStackTrace();
    }
    catch(LoginException le){
    
    le.printStackTrace();
    }
    
    }
    
    private static final class CallbackHandler implements javax.security.auth.callback.CallbackHandler
    {
    private String userid;
    private String password;
    private String url;
    
    public CallbackHandler(String userid, String password, String url)
    {
    this.userid = userid;
    this.password = password;
    this.url = url;
    }
    public void handle(Callback[] callbacks) throws UnsupportedCallbackException
    {
    for (int i = 0; i < callbacks.length; i++)
    {
    if (callbacks[i] instanceof TextOutputCallback)
    {
    TextOutputCallback toc = (TextOutputCallback)callbacks[i];
    System.err.println(“JAAS callback: ” + toc.getMessage());
    }
    else if (callbacks[i] instanceof NameCallback)
    {
    NameCallback nc = (NameCallback)callbacks[i];
    nc.setName(userid);
    }
    else if (callbacks[i] instanceof PasswordCallback)
    {
    PasswordCallback pc = (PasswordCallback)callbacks[i];
    pc.setPassword(password.toCharArray());
    }
    else if (callbacks[i] instanceof weblogic.security.auth.callback.URLCallback)
    {
    URLCallback uc = (URLCallback)callbacks[i];
    uc.setURL(url);
    }
    else
    {
    System.out.println(callbacks[i] + ” Unrecognized Callback”);
    throw new UnsupportedCallbackException(callbacks[i], “Unrecognized Callback”);
    }
    }
    }
    }
    }
  • 相关阅读:
    卷积神经网络
    卷积神经网络导览
    初识区块链——用JS构建你自己的区块链
    揭秘菜鸟仓储体系“大脑”:智能波次如何实现仓库降本提效?
    JQuery操作Iframe
    Spring MVC 学习笔记(二)
    SpringMVC各种视图
    Spring MVC 学习笔记(一)
    为什么在MySQL数据库中无法创建外键?(MyISAM和InnoDB详解)
    数据库访问性能优化
  • 原文地址:https://www.cnblogs.com/davidwang456/p/3794677.html
Copyright © 2011-2022 走看看