Hi Thomas,
One of the issues we experienced in the past is that the session is not updated or refreshed after signing the user in. In order to refresh the session, you would need to redirect the user in the Java action. Your Java action should look something like this:
ISession session = createSessionForUserAndRedirect(getContext(), getContext().getRuntimeRequest().get(), getContext().getRuntimeResponse().get(), userName, userPassword);
return session.getMendixObject();
In your extra code, you should have the following:
public static final String XASID_COOKIE = "XASID";
private static final String XAS_SESSION_ID = Core.getConfiguration().getSessionIdCookieName();
public static ISession createSessionForUserAndRedirect(IContext context, IMxRuntimeRequest request, IMxRuntimeResponse response, String userName, String userPassword) throws Exception {
IUser user = Core.getUser(getContext(), userName);
if(user!=null && Core.authenticate(getContext(), user, userPassword)) {
ISession session = myJavaAction.createSessionForUser(context, response, request, user);
return session;
}
else {
return null;
}
}
private static ISession createSessionForUser(IContext context, IMxRuntimeResponse response, IMxRuntimeRequest request, IUser user) throws Exception {
final ISession session = Core.initializeSession(user, null);
final String ua = request.getHeader("User-Agent");
session.setUserAgent(ua);
writeSessionCookies(response, session);
return session;
}
private static void writeSessionCookies(IMxRuntimeResponse response, ISession session) {
response.addCookie(XAS_SESSION_ID, session.getId().toString(), "/", "", -1, true);
response.addCookie(XASID_COOKIE, "0." + Core.getXASId(), "/", "", -1, true);
}
private static void redirectToIndex(IMxRuntimeRequest request, IMxRuntimeResponse response) {
response.setStatus(IMxRuntimeResponse.SEE_OTHER);
response.addHeader("Location", "{yourPageURL}");
}
Note that you would need to set the page that you want to redirect to URL
Another note is that myJavaAction (inside createSessionForUserAndRedirect) should be your JavaAction's name
Hope it helps!