1 7 8 package org.jboss.security.auth.spi; 9 10 import java.security.Principal ; 11 import java.security.acl.Group ; 12 import javax.security.auth.login.LoginException ; 13 14 import org.jboss.security.SimpleGroup; 15 import org.jboss.security.SimplePrincipal; 16 import org.jboss.security.auth.spi.UsernamePasswordLoginModule; 17 18 33 public class SimpleServerLoginModule extends UsernamePasswordLoginModule 34 { 35 private SimplePrincipal user; 36 private boolean guestOnly; 37 38 protected Principal getIdentity() 39 { 40 Principal principal = user; 41 if( principal == null ) 42 principal = super.getIdentity(); 43 return principal; 44 } 45 46 protected boolean validatePassword(String inputPassword, String expectedPassword) 47 { 48 boolean isValid = false; 49 if( inputPassword == null ) 50 { 51 guestOnly = true; 52 isValid = true; 53 user = new SimplePrincipal("guest"); 54 } 55 else 56 { 57 isValid = inputPassword.equals(expectedPassword); 58 } 59 return isValid; 60 } 61 62 protected Group [] getRoleSets() throws LoginException 63 { 64 Group [] roleSets = {new SimpleGroup("Roles")}; 65 if( guestOnly == false ) 66 roleSets[0].addMember(new SimplePrincipal("user")); 67 roleSets[0].addMember(new SimplePrincipal("guest")); 68 return roleSets; 69 } 70 71 protected String getUsersPassword() throws LoginException 72 { 73 return getUsername(); 74 } 75 76 } 77 | Popular Tags |