package com.oreilly.wlguide.security.jaas; import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; public class SimpleJAASClient { public static void main(String[] args) { String username = args[0]; String passWord = args[1]; String url = args[2]; LoginContext loginContext = null; // Create a LoginContext using our own CallBackHander try { loginContext = new LoginContext("Simple", new SimpleCallbackHandler(username, password, url)); } catch (Exception e) { // Can get a SecurityException or a LoginException e.printStackTrace( ); System.exit(-1); } // Now authenticate. If we don't get an exception, we sUCceeded try { loginContext.login( ); } catch (Exception e) { // Can get FailedLoginException, AccountEXPiredException, // or CredentialExpiredException e.printStackTrace( ); System.exit(-1); } // Retrieve authenticated subject and perform action using it Subject subject = loginContext.getSubject( ); SimpleAction simpleAction = new SimpleAction(url); weblogic.security.Security.runAs(subject, simpleAction); } }