1 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 ; 13 import javax.security.auth.login.LoginException ; 14 import javax.security.auth.spi.LoginModule ; 15 import java.security.Principal ; 16 import java.util.Hashtable ; 17 18 22 public class JBossPrincipalManager implements PrincipalManager{ 23 24 private static Log log = LogFactory.getLog(JBossPrincipalManager.class); 25 26 27 public void setThreadPrincipal(String login, String password) { 28 Principal principal = new DefaultPrincipal(login); 29 Subject subject = new Subject (); 30 subject.getPrincipals().add(principal); 31 LoginModule loginModule = new ClientLoginModule(); 32 33 Hashtable options = new Hashtable (2); 34 options.put("multi-thread", "true"); 35 options.put("password-stacking", "useFirstPass"); 36 37 Hashtable sharedState = new Hashtable (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 e) { 46 String msg = "Fatal error during the set of the principal for " + login; 47 log.fatal(msg,e); 48 throw new RuntimeException ( msg + " : " + e.getLocalizedMessage()); 49 } 50 51 } 52 53 public void setJVMPrincipal(String login, String password) { 54 throw new UnsupportedOperationException ("Not implemented"); 55 } 56 } | Popular Tags |