1 7 package org.jboss.security.auth.spi; 8 9 import java.util.Map ; 10 import java.util.HashSet ; 11 import javax.security.auth.Subject ; 12 import javax.security.auth.callback.CallbackHandler ; 13 import javax.security.auth.spi.LoginModule ; 14 15 import org.jboss.security.SecurityAssociation; 16 import org.jboss.security.SimplePrincipal; 17 import org.jboss.security.RunAsIdentity; 18 19 26 public class RunAsLoginModule implements LoginModule 27 { 28 private String roleName; 29 private String principalName; 30 private boolean pushedRole; 31 32 35 public void initialize(Subject subject, CallbackHandler handler, 36 Map sharedState, Map options) 37 { 38 roleName = (String ) options.get("roleName"); 39 if( roleName == null ) 40 roleName = "nobody"; 41 42 principalName = (String ) options.get("principalName"); 43 if( principalName == null ) 44 principalName = "nobody"; 45 } 46 47 50 public boolean login() 51 { 52 RunAsIdentity runAsRole = new RunAsIdentity(roleName, principalName); 53 SecurityAssociation.pushRunAsIdentity(runAsRole); 54 pushedRole = true; 55 return true; 56 } 57 58 60 public boolean commit() 61 { 62 return abort(); 63 } 64 65 68 public boolean abort() 69 { 70 if( pushedRole == false ) 71 return false; 72 73 SecurityAssociation.popRunAsIdentity(); 74 return true; 75 } 76 77 public boolean logout() 78 { 79 return true; 80 } 81 } 82 | Popular Tags |