1 18 19 package org.apache.activemq.security; 20 21 import org.apache.activemq.jaas.GroupPrincipal; 22 import org.apache.activemq.jaas.UserPrincipal; 23 24 import java.util.Map ; 25 26 import javax.security.auth.Subject ; 27 import javax.security.auth.callback.CallbackHandler ; 28 import javax.security.auth.login.FailedLoginException ; 29 import javax.security.auth.login.LoginException ; 30 import javax.security.auth.spi.LoginModule ; 31 32 public class StubLoginModule implements LoginModule { 33 public static final String ALLOW_LOGIN_PROPERTY = "org.apache.activemq.jaas.stubproperties.allow_login"; 34 public static final String USERS_PROPERTY = "org.apache.activemq.jaas.stubproperties.users"; 35 public static final String GROUPS_PROPERTY = "org.apache.activemq.jaas.stubproperties.groups"; 36 37 private Subject subject = null; 38 39 private String userNames[] = null; 40 private String groupNames[] = null; 41 private boolean allowLogin = false; 42 43 public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { 44 String allowLoginString = (String )(options.get(ALLOW_LOGIN_PROPERTY)); 45 String usersString = (String )(options.get(USERS_PROPERTY)); 46 String groupsString = (String )(options.get(GROUPS_PROPERTY)); 47 48 this.subject = subject; 49 50 allowLogin = Boolean.parseBoolean(allowLoginString); 51 userNames = usersString.split(","); 52 groupNames = groupsString.split(","); 53 } 54 55 public boolean login() throws LoginException { 56 if (!allowLogin) { 57 throw new FailedLoginException ("Login was not allowed (as specified in configuration)."); 58 } 59 60 return true; 61 } 62 63 public boolean commit() throws LoginException { 64 if (!allowLogin) { 65 throw new FailedLoginException ("Login was not allowed (as specified in configuration)."); 66 } 67 68 for (int i = 0; i < userNames.length; ++i) { 69 if (userNames[i].length() > 0 ) { 70 subject.getPrincipals().add(new UserPrincipal(userNames[i])); 71 } 72 } 73 74 for (int i = 0; i < groupNames.length; ++i) { 75 if (groupNames[i].length() > 0) { 76 subject.getPrincipals().add(new GroupPrincipal(groupNames[i])); 77 } 78 } 79 80 return true; 81 } 82 83 public boolean abort() throws LoginException { 84 return true; 85 } 86 87 public boolean logout() throws LoginException { 88 subject.getPrincipals().clear(); 89 90 return true; 91 } 92 93 } 94 | Popular Tags |