SUMMARY:
In some circumstances, users may want to direct some users directly into a particular project while giving other the option to pick the desired project. When using the "Login First" workflow, this is normally not an option. The following code snippet will force all users who belong to the group "Test Group" into a particular group, while allowing all other to go through the normal out-of-the box login workflow:
public class ByPassProjectsPage extends AbstractExternalSecurity {
boolean bypassProjectsPage = false;
String sessionState = null;
public boolean processMSTRLoginForm(RequestKeys rk, ContainerServices cs, LoginForm lf, int reason) {
if (lf.getLoginName() != null) {
//Get this from the LoginForm object
if (reason == 4)
{
WebUser user = null;
WebIServerSession mySession = WebObjectsFactory.getInstance().getIServerSession();
mySession.setServerName("ServerName");
mySession.setServerPort(0);
mySession.setProjectName("Project");
mySession.setLogin(lf.getLoginName());
mySession.setPassword(lf.getPassword());
try {
user = (WebUser) mySession.getUserInfo(true);
} catch (WebObjectsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebUserList parentList = null;
parentList = user.getParents();
Enumeration userEnum = parentList.elements();
WebUserEntity userGroup = null;
while (userEnum.hasMoreElements()) {
userGroup = (WebUserEntity) userEnum.nextElement();
System.out.println(userGroup.getName());
if (userGroup.getName().equals("Test Group")) {
bypassProjectsPage = true;
System.out.println("bypass projects page");
sessionState = mySession.saveState(EnumWebPersistableState.TYPICAL_STATE_INFO);
System.out.println(mySession.saveState(EnumWebPersistableState.TYPICAL_STATE_INFO));
return false;
}
}
}
return true;
}
return super.processMSTRLoginForm(rk, cs, lf, reason);
}
public String getFailureURL(int arg0, ContainerServices arg1) {
System.out.println("getFailureURL");
if (bypassProjectsPage) {
return "mstrWeb?evt=3010&mstrSmgr=" + sessionState;
}
return super.getFailureURL(arg0, arg1);
}
}