[jbossseam-issues] [JBoss JIRA] Updated: (JBSEAM-2164) Improve exception chaining in SeamLoginModule
Yannick Lazzari (JIRA)
jira-events at lists.jboss.org
Fri Oct 26 09:27:01 EDT 2007
[ http://jira.jboss.com/jira/browse/JBSEAM-2164?page=all ]
Yannick Lazzari updated JBSEAM-2164:
------------------------------------
Component/s: Security
Affects Version/s: 2.0.0.CR3
> Improve exception chaining in SeamLoginModule
> ---------------------------------------------
>
> Key: JBSEAM-2164
> URL: http://jira.jboss.com/jira/browse/JBSEAM-2164
> Project: JBoss Seam
> Issue Type: Feature Request
> Components: Security
> Affects Versions: 2.0.0.CR3
> Reporter: Yannick Lazzari
> Priority: Minor
>
> This an improvement request in the SeamLoginModule class to properly chain exceptions when throwing LoginExceptions in the login method. See code below:
> public boolean login()
> throws LoginException
> {
> try
> {
> NameCallback cbName = new NameCallback("Enter username");
> PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
>
> // Get the username and password from the callback handler
> callbackHandler.handle(new Callback[] { cbName, cbPassword });
> username = cbName.getName();
> }
> catch (Exception ex)
> {
> log.error("Error logging in", ex);
> throw new LoginException(ex.getMessage());
> }
>
> MethodExpression mb = Identity.instance().getAuthenticateMethod();
> if (mb==null)
> {
> throw new IllegalStateException("No authentication method defined - please define <security:authenticate-method/> for <security:identity/> in components.xml");
> }
>
> try
> {
> return (Boolean) mb.invoke();
> }
> catch (Exception ex)
> {
> log.error("Error invoking login method", ex);
> throw new LoginException(ex.getMessage());
> }
> }
>
> In both instances where a LoginException is thrown, only the message is passed to the constructor of the LoginException. I know that the LoginException does not overload the constructor to pass a cause directly but we can use the initCause method instead:
> LoginException loginException = new LoginException();
> loginException.initCause(originalException);
> throw loginException;
>
> If people use typed exceptions in their authenticator method to express different reasons why the login attempt failed, it's impossible right now to get that original exception.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list