Enhanced error detection at startup time. Added support for handling null usernames and passwords.

This commit is contained in:
Ben Alex 2004-03-28 12:01:51 +00:00
parent 2e1b4b4ffc
commit 68ee9aaabb
1 changed files with 37 additions and 19 deletions

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.adapters.jboss;
import net.sf.acegisecurity.Authentication;
@ -56,23 +55,34 @@ import javax.security.auth.login.LoginException;
* @version $Id$
*/
public class JbossAcegiLoginModule extends AbstractServerLoginModule {
//~ Instance fields ========================================================
private AuthenticationManager authenticationManager;
private Principal identity;
private String key;
private char[] credential;
//~ Methods ================================================================
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map sharedState, Map options) {
super.initialize(subject, callbackHandler, sharedState, options);
this.key = (String) options.get("key");
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext((String) options
.get("appContextLocation"));
if ((key == null) || "".equals(key)) {
throw new IllegalArgumentException("key must be defined");
}
String appContextLocation = (String) options.get("appContextLocation");
if ((appContextLocation == null) || "".equals(appContextLocation)) {
throw new IllegalArgumentException(
"appContextLocation must be defined");
}
if (Thread.currentThread().getContextClassLoader().getResource(appContextLocation) == null) {
throw new IllegalArgumentException("Cannot locate " +
appContextLocation);
}
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(appContextLocation);
Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true);
if (beans.size() == 0) {
@ -94,8 +104,16 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
if ((username == null) && (password == null)) {
identity = null;
super.log.trace("Authenticating as unauthenticatedIdentity="
+ identity);
super.log.trace("Authenticating as unauthenticatedIdentity=" +
identity);
}
if (username == null) {
username = "";
}
if (password == null) {
password = "";
}
if (identity == null) {
@ -127,8 +145,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
}
super.loginOk = true;
super.log.trace("User '" + identity + "' authenticated, loginOk="
+ loginOk);
super.log.trace("User '" + identity + "' authenticated, loginOk=" +
loginOk);
return true;
}
@ -158,8 +176,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
// prompt for a username and password
if (callbackHandler == null) {
throw new LoginException("Error: no CallbackHandler available "
+ "to collect authentication information");
throw new LoginException("Error: no CallbackHandler available " +
"to collect authentication information");
}
NameCallback nc = new NameCallback("User name: ", "guest");
@ -184,8 +202,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule {
} catch (java.io.IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException("CallbackHandler does not support: "
+ uce.getCallback());
throw new LoginException("CallbackHandler does not support: " +
uce.getCallback());
}
info[0] = username;