|
|
|
@ -12,7 +12,6 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package net.sf.acegisecurity.adapters.jboss; |
|
|
|
package net.sf.acegisecurity.adapters.jboss; |
|
|
|
|
|
|
|
|
|
|
|
import net.sf.acegisecurity.Authentication; |
|
|
|
import net.sf.acegisecurity.Authentication; |
|
|
|
@ -45,7 +44,7 @@ import javax.security.auth.login.LoginException; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Adapter to enable JBoss to authenticate via the Acegi Security System for |
|
|
|
* Adapter to enable JBoss to authenticate via the Acegi Security System for |
|
|
|
* Spring. |
|
|
|
* Spring. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* Returns a {@link PrincipalAcegiUserToken} to JBoss' authentication system, |
|
|
|
* Returns a {@link PrincipalAcegiUserToken} to JBoss' authentication system, |
|
|
|
* which is subsequently available from |
|
|
|
* which is subsequently available from |
|
|
|
@ -56,23 +55,34 @@ import javax.security.auth.login.LoginException; |
|
|
|
* @version $Id$ |
|
|
|
* @version $Id$ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
//~ Instance fields ========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AuthenticationManager authenticationManager; |
|
|
|
private AuthenticationManager authenticationManager; |
|
|
|
private Principal identity; |
|
|
|
private Principal identity; |
|
|
|
private String key; |
|
|
|
private String key; |
|
|
|
private char[] credential; |
|
|
|
private char[] credential; |
|
|
|
|
|
|
|
|
|
|
|
//~ Methods ================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void initialize(Subject subject, CallbackHandler callbackHandler, |
|
|
|
public void initialize(Subject subject, CallbackHandler callbackHandler, |
|
|
|
Map sharedState, Map options) { |
|
|
|
Map sharedState, Map options) { |
|
|
|
super.initialize(subject, callbackHandler, sharedState, options); |
|
|
|
super.initialize(subject, callbackHandler, sharedState, options); |
|
|
|
|
|
|
|
|
|
|
|
this.key = (String) options.get("key"); |
|
|
|
this.key = (String) options.get("key"); |
|
|
|
|
|
|
|
|
|
|
|
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext((String) options |
|
|
|
if ((key == null) || "".equals(key)) { |
|
|
|
.get("appContextLocation")); |
|
|
|
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); |
|
|
|
Map beans = ctx.getBeansOfType(AuthenticationManager.class, true, true); |
|
|
|
|
|
|
|
|
|
|
|
if (beans.size() == 0) { |
|
|
|
if (beans.size() == 0) { |
|
|
|
@ -94,8 +104,16 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
|
|
|
|
|
|
|
|
if ((username == null) && (password == null)) { |
|
|
|
if ((username == null) && (password == null)) { |
|
|
|
identity = null; |
|
|
|
identity = null; |
|
|
|
super.log.trace("Authenticating as unauthenticatedIdentity=" |
|
|
|
super.log.trace("Authenticating as unauthenticatedIdentity=" + |
|
|
|
+ identity); |
|
|
|
identity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (username == null) { |
|
|
|
|
|
|
|
username = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (password == null) { |
|
|
|
|
|
|
|
password = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (identity == null) { |
|
|
|
if (identity == null) { |
|
|
|
@ -127,8 +145,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
super.loginOk = true; |
|
|
|
super.loginOk = true; |
|
|
|
super.log.trace("User '" + identity + "' authenticated, loginOk=" |
|
|
|
super.log.trace("User '" + identity + "' authenticated, loginOk=" + |
|
|
|
+ loginOk); |
|
|
|
loginOk); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -139,7 +157,7 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
|
|
|
|
|
|
|
|
protected Group[] getRoleSets() throws LoginException { |
|
|
|
protected Group[] getRoleSets() throws LoginException { |
|
|
|
SimpleGroup roles = new SimpleGroup("Roles"); |
|
|
|
SimpleGroup roles = new SimpleGroup("Roles"); |
|
|
|
Group[] roleSets = {roles}; |
|
|
|
Group[] roleSets = { roles }; |
|
|
|
|
|
|
|
|
|
|
|
if (this.identity instanceof Authentication) { |
|
|
|
if (this.identity instanceof Authentication) { |
|
|
|
Authentication user = (Authentication) this.identity; |
|
|
|
Authentication user = (Authentication) this.identity; |
|
|
|
@ -154,17 +172,17 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected String[] getUsernameAndPassword() throws LoginException { |
|
|
|
protected String[] getUsernameAndPassword() throws LoginException { |
|
|
|
String[] info = {null, null}; |
|
|
|
String[] info = { null, null }; |
|
|
|
|
|
|
|
|
|
|
|
// prompt for a username and password
|
|
|
|
// prompt for a username and password
|
|
|
|
if (callbackHandler == null) { |
|
|
|
if (callbackHandler == null) { |
|
|
|
throw new LoginException("Error: no CallbackHandler available " |
|
|
|
throw new LoginException("Error: no CallbackHandler available " + |
|
|
|
+ "to collect authentication information"); |
|
|
|
"to collect authentication information"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NameCallback nc = new NameCallback("User name: ", "guest"); |
|
|
|
NameCallback nc = new NameCallback("User name: ", "guest"); |
|
|
|
PasswordCallback pc = new PasswordCallback("Password: ", false); |
|
|
|
PasswordCallback pc = new PasswordCallback("Password: ", false); |
|
|
|
Callback[] callbacks = {nc, pc}; |
|
|
|
Callback[] callbacks = { nc, pc }; |
|
|
|
String username = null; |
|
|
|
String username = null; |
|
|
|
String password = null; |
|
|
|
String password = null; |
|
|
|
|
|
|
|
|
|
|
|
@ -184,8 +202,8 @@ public class JbossAcegiLoginModule extends AbstractServerLoginModule { |
|
|
|
} catch (java.io.IOException ioe) { |
|
|
|
} catch (java.io.IOException ioe) { |
|
|
|
throw new LoginException(ioe.toString()); |
|
|
|
throw new LoginException(ioe.toString()); |
|
|
|
} catch (UnsupportedCallbackException uce) { |
|
|
|
} catch (UnsupportedCallbackException uce) { |
|
|
|
throw new LoginException("CallbackHandler does not support: " |
|
|
|
throw new LoginException("CallbackHandler does not support: " + |
|
|
|
+ uce.getCallback()); |
|
|
|
uce.getCallback()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
info[0] = username; |
|
|
|
info[0] = username; |
|
|
|
|