JAAS LOGIN in WEBLOGIC server--reference

Source: Internet
Author: User

The Java authentication and Authorization Service (JAAS) is a standard extension to the security in the J2SE development K It 5.0. JAAS provides the ability to enforce access controls based on user identity. JAAS is provided in WebLogic Server as a 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 INS Tances and is responsible for the management of the completion status of each configured provider.

//Jaaslogin.javaImportJavax.security.auth.Subject;Importjavax.security.auth.callback.*;Importjavax.security.auth.login.*;ImportWeblogic.security.auth.callback.URLCallback; Public classjaaslogin{Private Static Final classconfiginfo{StaticString USERID ="WebLogic";StaticString PASSWORD ="WebLogic";StaticString URL = "T3://10.10.71.79:7001?;StaticString jaas_string ="Other";} Public Static voidMain (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=NewLoginContext (Configinfo.jaas_string,NewJaaslogin.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 classCallbackHandlerImplementsjavax.security.auth.callback.callbackhandler{PrivateString userid;PrivateString password;PrivateString URL; PublicCallbackHandler (string userid, string password, string url) { This. UserID =userid; This. Password =password; This. url =URL;} Public voidHandle (callback[] callbacks)throwsunsupportedcallbackexception{ for(inti = 0; i < callbacks.length; i++){if(Callbacks[i]instanceoftextoutputcallback) {Textoutputcallback TOC=(Textoutputcallback) callbacks[i]; System.err.println ("JAAS callback:"+toc.getmessage ());}Else if(Callbacks[i]instanceofnamecallback) {NameCallback NC=(NameCallback) callbacks[i];nc.setname (userid);}Else if(Callbacks[i]instanceofpasswordcallback) {PasswordCallback PC=(PasswordCallback) callbacks[i];p C.setpassword (Password.tochararray ());}Else if(Callbacks[i]instanceofweblogic.security.auth.callback.URLCallback) {Urlcallback UC=(urlcallback) callbacks[i];uc.seturl (URL);}Else{System.out.println (callbacks[i]+"Unrecognized Callback");Throw Newunsupportedcallbackexception (Callbacks[i], "unrecognized Callback"); }}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.