KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > remoting > util > impl > JBossPrincipalManager


1 /**
2  * @licence.bsf@
3  */

4 package org.bsf.remoting.util.impl;
5
6 import org.bsf.remoting.util.DefaultPrincipal;
7 import org.bsf.remoting.util.PrincipalManager;
8 import org.jboss.security.ClientLoginModule;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import javax.security.auth.Subject JavaDoc;
13 import javax.security.auth.login.LoginException JavaDoc;
14 import javax.security.auth.spi.LoginModule JavaDoc;
15 import java.security.Principal JavaDoc;
16 import java.util.Hashtable JavaDoc;
17
18 /**
19  * @author Gaetan Zoritchak
20  * @version@
21  */

22 public class JBossPrincipalManager implements PrincipalManager{
23
24     private static Log log = LogFactory.getLog(JBossPrincipalManager.class);
25
26
27     public void setThreadPrincipal(String JavaDoc login, String JavaDoc password) {
28         Principal principal = new DefaultPrincipal(login);
29         Subject JavaDoc subject = new Subject JavaDoc();
30         subject.getPrincipals().add(principal);
31         LoginModule loginModule = new ClientLoginModule();
32
33         Hashtable JavaDoc options = new Hashtable JavaDoc(2);
34         options.put("multi-thread", "true");
35         options.put("password-stacking", "useFirstPass");
36
37         Hashtable JavaDoc sharedState = new Hashtable JavaDoc(2);
38         sharedState.put("javax.security.auth.login.name", login);
39         sharedState.put("javax.security.auth.login.password", password);
40
41         loginModule.initialize(subject, null, sharedState, options);
42
43         try {
44             loginModule.login();
45         } catch (LoginException JavaDoc e) {
46             String JavaDoc msg = "Fatal error during the set of the principal for " + login;
47             log.fatal(msg,e);
48             throw new RuntimeException JavaDoc( msg + " : " + e.getLocalizedMessage());
49         }
50
51     }
52
53     public void setJVMPrincipal(String JavaDoc login, String JavaDoc password) {
54         throw new UnsupportedOperationException JavaDoc("Not implemented");
55     }
56 }
Popular Tags