1 22 package org.jboss.test.security.ejb; 23 24 import java.security.acl.Group ; 25 import java.security.Principal ; 26 import javax.security.auth.login.LoginException ; 27 import org.jboss.security.auth.spi.UsernamePasswordLoginModule; 28 import org.jboss.security.SimpleGroup; 29 import org.jboss.security.SimplePrincipal; 30 31 36 public class CustomPrincipalLoginModule extends UsernamePasswordLoginModule 37 { 38 private CustomPrincipalImpl caller; 39 40 public boolean login() throws LoginException 41 { 42 if (super.login()) 43 { 44 caller = new CustomPrincipalImpl(getUsername()); 45 return true; 46 } 47 return false; 48 } 49 50 protected Principal getIdentity() 51 { 52 Principal identity = caller; 53 if( identity == null ) 54 identity = super.getIdentity(); 55 return identity; 56 } 57 58 protected Group [] getRoleSets() throws LoginException 59 { 60 try 61 { 62 Group roles = new SimpleGroup("Roles"); 64 Group callerPrincipal = new SimpleGroup("CallerPrincipal"); 66 Group [] groups = {roles, callerPrincipal}; 67 log.info("Getting roles for user=" + getUsername()); 68 roles.addMember(new SimplePrincipal("Echo")); 70 callerPrincipal.addMember(caller); 72 return groups; 73 } 74 catch (Exception e) 75 { 76 log.error("Failed to obtain groups for user=" + getUsername(), e); 77 throw new LoginException (e.toString()); 78 } 79 } 80 81 protected String getUsersPassword() 82 { 83 return "theduke"; 84 } 85 86 } | Popular Tags |