The below code is a Tomcat Custom Realm Authentication code where if user gives password as "test" it logs in successfully
how can i modify this program such that if i have 5 user and each with different password stored in an array
and also tell me the way of execution of this realm which fuction is executed first and who calls these functions
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import org.apache.catalina.realm.RealmBase;
import org.apache.catalina.realm.GenericPrincipal;
public class NewRealm extends RealmBase
{
private String username;
private String password;
@Override
public Principal authenticate(String username, String credentials)
{
this.username = username;
this.password = credentials;
if (this.username.equals(this.password))
{
return getPrincipal(username);
}
else
{
return null;
}
}
@Override
protected String getName() {
return username;
}
@Override
protected String getPassword(String username) {
return "test";
}
@Override
protected Principal getPrincipal(String string) {
List<String> roles = new ArrayList<String>();
roles.add("user");
Principal principal = new GenericPrincipal(username,"test",roles);
return principal;
}
}