Search in sources :

Example 1 with SSOUtils

use of net.jforum.sso.SSOUtils in project jforum2 by rafaelsteil.

the class ControllerUtils method checkSSO.

/**
 * Checks for user authentication using some SSO implementation
 * @param userSession UserSession
 */
protected void checkSSO(UserSession userSession) {
    try {
        SSO sso = (SSO) Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
        String username = sso.authenticateUser(JForumExecutionContext.getRequest());
        if (username == null || username.trim().equals("")) {
            userSession.makeAnonymous();
        } else {
            SSOUtils utils = new SSOUtils();
            if (!utils.userExists(username)) {
                SessionContext session = JForumExecutionContext.getRequest().getSessionContext();
                String email = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_EMAIL_ATTRIBUTE));
                String password = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_PASSWORD_ATTRIBUTE));
                if (email == null) {
                    email = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_EMAIL);
                }
                if (password == null) {
                    password = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_PASSWORD);
                }
                utils.register(password, email);
            }
            this.configureUserSession(userSession, utils.getUser());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new ForumException("Error while executing SSO actions: " + e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) SessionContext(net.jforum.context.SessionContext) SSOUtils(net.jforum.sso.SSOUtils) SSO(net.jforum.sso.SSO) DatabaseException(net.jforum.exceptions.DatabaseException) ForumException(net.jforum.exceptions.ForumException)

Aggregations

SessionContext (net.jforum.context.SessionContext)1 DatabaseException (net.jforum.exceptions.DatabaseException)1 ForumException (net.jforum.exceptions.ForumException)1 SSO (net.jforum.sso.SSO)1 SSOUtils (net.jforum.sso.SSOUtils)1