package net.jforum.sso;
import javax.servlet.http.Cookie;
import net.jforum.context.RequestContext;
import net.jforum.JForumExecutionContext;
import net.jforum.ControllerUtils;
import net.jforum.entities.UserSession;
import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;
import org.apache.log4j.Logger;
public class CookieUserSSO implements SSO {
static final Logger logger = Logger.getLogger(CookieUserSSO.class.getName());
public String authenticateUser(RequestContext request) {
// myapp login cookie, contain logged username
Cookie myCookie = ControllerUtils.getCookie(
SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER));
String username = null;
if (myCookie != null) {
username = myCookie.getValue();
}
return username; // jforum username
}
public boolean isSessionValid(UserSession userSession, RequestContext request) {
Cookie SSOCookie = ControllerUtils.getCookie(
SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER)); // myapp login cookie
String remoteUser = null;
if (SSOCookie != null) {
remoteUser = SSOCookie.getValue(); // jforum username
}
// user has since logged out
if(remoteUser == null &&
userSession.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
return false;
// user has since logged in
} else if(remoteUser != null &&
userSession.getUserId() == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
return false;
// user has changed user
} else if(remoteUser != null && !remoteUser.equals(userSession.getUsername())) {
return false;
}
return true; // myapp user and forum user the same
}
}
authentication.type=sso
sso.implementation=net.jforum.sso.CookieUserSSO
sso.redirect=http://member.andowson.com/login.jsp
cookie.name.user=username
檔案名稱 | CookieUserSSO.java |
描述 | CookieUserSSO.java |
檔案大小 | 2 Kbytes |
下載次數 | 50 次 |
下載 |
檔案名稱 | CookieUserSSO.class |
描述 | CookieUserSSO.class |
檔案大小 | 2 Kbytes |
下載次數 | 39 次 |
下載 |