From: Sternagel A. (PN-SYS/PE) <Annegret.Sternagel@Tenovis.com> - 2002-01-30 15:16:45
|
Hello Ed, you said you are using client-login. But you create a LoginContext = using "Carrier". The LoginContext must be created with the configurationname = (to use in auth.conf), username and password will be set in the = Callbackhandler. So jboss can't find "Carrier" in auth.conf and uses "other". Try=20 lc =3D new LoginContext("Client-login", handler); Annegret -----Urspr=FCngliche Nachricht----- Von: Ed Brown [mailto:ed...@to...] Gesendet: Mittwoch, 30. Januar 2002 15:22 An: jbo...@li... Betreff: Re: [JBoss-user] JAAS Example Not Working Quoting Quique Ruiz-Valenciano <qr...@is...>: > >=20 > > I'm trying to understand security in JBoss. > >=20 > > I took the example from the JBoss-2.4.x PDF and stripped it down. = When > I run=20 > > it, I get the following exception: > >=20 > > Failed toload user/spasswords/role files > > java.io.IOException: Properties file usres.properties not found. > > <stack trace omitted> > >=20 > > I have a client (not a servlet, jsp, or ejb) trying to connect to = an > EJB.=20 > >=20 > > The failure occured on the line=20 > > lc.login() > >=20 > > where lc is defined as > >=20 > > LoginContext lc =3D new LoginContext("user", handler); > >=20 > > java.security.auth.login.config property is defined and points to > auth.conf. > >=20 > > Any suggestions on this one? Looking at the archives shows previous > errors like=20 > > this, but no solutions to my case when the client is a "true = client" > and not a=20 > > servlet or another EJB. > >=20 >=20 > Hello Ed, >=20 > Could you send us the auth.conf file? I use client-login. My auth.conf file follows: simple { // Very simple login module:=20 // any user name is accepted. // password should either coincide with user name or be null,=20 // all users have role "guest",=20 // users with non-null password also have role "user" org.jboss.security.auth.spi.SimpleServerLoginModule required; }; // Used by clients within the application server VM such as // mbeans and servlets that access EJBs. client-login { org.jboss.security.ClientLoginModule required; }; // The default server login module other { // A simple server login module, which can be used when the number=20 // of users is relatively small. It uses two properties files: // users.properties, which holds users (key) and their password (value). // roles.properties, which holds users (key) and a = comma-separated list=20 of their roles (value). // The unauthenticatedIdentity property defines the name of the principal // that will be used when a null username and password are = presented as is // the case for an unuathenticated web client or MDB. If you want = to // allow such users to be authenticated add the property, e.g., // unauthenticatedIdentity=3D"nobody" org.jboss.security.auth.spi.UsersRolesLoginModule required ; }; =20 ----------- Here's teh exact stack trace: RROR [main] (?:?) - Failed to load users/passwords/role files java.io.IOException: Properties file users.properties not found at org.jboss.security.auth.spi.UsersRolesLoginModule.loadProperties (UsersRolesLoginModule.java:199) at org.jboss.security.auth.spi.UsersRolesLoginModule.loadUsers (UsersRolesLoginModule.java:180) at org.jboss.security.auth.spi.UsersRolesLoginModule.initialize (UsersRolesLoginModule.java:79) at java.lang.reflect.Method.invoke(Native Method) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:582) at javax.security.auth.login.LoginContext.access$000 (LoginContext.java:125) at javax.security.auth.login.LoginContext$3.run(LoginContext.java:531) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.LoginContext.invokeModule (LoginContext.java:528) at javax.security.auth.login.LoginContext.login(LoginContext.java:449) at sectest.TestLogin.<init>(TestLogin.java:82) at sectest.TestLogin.main(TestLogin.java:240) javax.security.auth.login.LoginException: Missing users.properties = file. at org.jboss.security.auth.spi.UsersRolesLoginModule.login (UsersRolesLoginModule.java:105) at java.lang.reflect.Method.invoke(Native Method) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:595) at javax.security.auth.login.LoginContext.access$000 (LoginContext.java:125)-- Failed initializing bean access. at javax.security.auth.login.LoginContext$3.run(LoginContext.java:531) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.LoginContext.invokeModule (LoginContext.java:528) at javax.security.auth.login.LoginContext.login(LoginContext.java:449) ---------------- Here's the client code: public class TestLogin { private static final String ERROR_NULL_REMOTE =3D "Remote interface reference=20 is null. It must be created by calling one of the Home interface = methods=20 first."; private static final int MAX_OUTPUT_LINE_LENGTH =3D 100; private boolean logging =3D true; private LoginHome loginHome =3D null; private Login login =3D null; static class AppCallbackHandler implements CallbackHandler { private String username; private char[] password; public AppCallbackHandler(String username, char[] password) { this.username =3D username; this.password =3D password; } public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException { for (int i =3D 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { System.out.println("handle " + i + ": callbacks["+i+"] = instanceof=20 NameCallback"); NameCallback nc =3D (NameCallback)callbacks[i]; System.out.println("setting username to Carrier"); nc.setName(username); } else if (callbacks[i] instanceof PasswordCallback) { System.out.println("handle " + i + ": callbacks["+i+"] = instanceof=20 PasswordCallback"); PasswordCallback pc =3D (PasswordCallback)callbacks[i]; System.out.println("setting username to Carrier"); pc.setPassword(password); } else { System.out.println("handle: unrecognized callback " + = callbacks [i].getClass().getName()); throw new UnsupportedCallbackException(callbacks[i], = "Unrecognized Callback"); } } } } /**Construct the EJB test client*/ public TestLogin() { long startTime =3D 0; if (logging) { log("Initializing bean access."); startTime =3D System.currentTimeMillis(); } try { AppCallbackHandler handler =3D new AppCallbackHandler ("Carrier", "Carrier".toCharArray()); System.out.println("handler is " + handler); LoginContext lc =3D new LoginContext("Carrier", handler); System.out.println("Created LoginContext"); lc.login(); /* String namingFactory =3D = "org.jnp.interfaces.NamingContextFactory"; String providerUrl =3D "jnp://mdcsandbox1:9901"; String factoryUrl =3D "org.jboss.naming:org.jnp.interfaces"; Hashtable props =3D new Hashtable(); props.put(Context.INITIAL_CONTEXT_FACTORY, namingFactory); props.put(Context.PROVIDER_URL, providerUrl); props.put(Context.URL_PKG_PREFIXES, factoryUrl); //get naming context Context ctx =3D new InitialContext(props); */ Context ctx =3D new InitialContext(); //look up jndi name Object ref =3D ctx.lookup("Login"); //cast to Home interface loginHome =3D (LoginHome) PortableRemoteObject.narrow(ref, LoginHome.class); if (logging) { long endTime =3D System.currentTimeMillis(); log("Succeeded initializing bean access."); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed initializing bean access."); } e.printStackTrace(); } } =20 //----------------------------------------------------------------------= ---- -- // Methods that use Home interface methods to generate a Remote = interface=20 reference =20 //----------------------------------------------------------------------= ---- -- public Login create() { long startTime =3D 0; if (logging) { log("Calling create()"); startTime =3D System.currentTimeMillis(); } try { login =3D loginHome.create(); if (logging) { long endTime =3D System.currentTimeMillis(); log("Succeeded: create()"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: create()"); } e.printStackTrace(); } if (logging) { log("Return value from create(): " + login + "."); } return login; } public Login create(String user, String password) { long startTime =3D 0; if (logging) { log("Calling create(" + user + ", " + password + ")"); startTime =3D System.currentTimeMillis(); } try { login =3D loginHome.create(user, password); if (logging) { long endTime =3D System.currentTimeMillis(); log("Succeeded: create(" + user + ", " + password + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: create(" + user + ", " + password + ")"); } e.printStackTrace(); } if (logging) { log("Return value from create(" + user + ", " + password + "): " = + login=20 + "."); } return login; } =20 //----------------------------------------------------------------------= ---- -- // Methods that use Remote interface methods to access data through = the bean =20 //----------------------------------------------------------------------= ---- -- public String validate() { String returnValue =3D ""; if (login =3D=3D null) { System.out.println("Error in validate(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime =3D 0; if (logging) { log("Calling validate()"); startTime =3D System.currentTimeMillis(); } try { returnValue =3D login.validate(); if (logging) { long endTime =3D System.currentTimeMillis(); log("Succeeded: validate()"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: validate()"); } e.printStackTrace(); } if (logging) { log("Return value from validate(): " + returnValue + "."); } return returnValue; } public void testRemoteCallsWithDefaultArguments() { if (login =3D=3D null) { System.out.println("Error in = testRemoteCallsWithDefaultArguments(): " +=20 ERROR_NULL_REMOTE); return ; } validate(); } =20 //----------------------------------------------------------------------= ---- -- // Utility Methods =20 //----------------------------------------------------------------------= ---- -- private void log(String message) { if (message =3D=3D null) { System.out.println("-- null"); return ; } if (message.length() > MAX_OUTPUT_LINE_LENGTH) { System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH)=20 + " ..."); } else { System.out.println("-- " + message); } } /**Main method*/ public static void main(String[] args) { TestLogin client =3D new TestLogin(); // Use the client object to call one of the Home interface wrappers // above, to create a Remote interface reference to the bean. // If the return value is of the Remote interface type, you can use = it // to access the remote interface methods. You can also just use = the // client object to call the Remote interface wrappers. try { client.create("Carrier", "Carrier"); client.validate(); } catch(Exception e) { e.printStackTrace(); } } } Ed Brown ________________________________________________________________________= _ This mail sent via toadmail.com, web e-mail @ ToadNet - want to go = fast? http://www.toadmail.com _______________________________________________ JBoss-user mailing list JBo...@li... https://lists.sourceforge.net/lists/listinfo/jboss-user |