All Downloads are FREE. Search and download functionalities are using the official Maven repository.

clime.messadmin.providers.user.KnownLocations Maven / Gradle / Ivy

Go to download

Notification system and Session administration for J2EE Web Applications

There is a newer version: 4.1.1
Show newest version
/**
 * 
 */
package clime.messadmin.providers.user;

import javax.servlet.http.HttpSession;

import clime.messadmin.providers.spi.UserNameProvider;

/**
 * Search "known locations" for user name
 * @author Cédrik LIME
 */
public class KnownLocations implements UserNameProvider {
	/**
	 * The session attributes key under which the user
	 * name is stored, if any.
	 * 
	 * Lower and upper-case strings will be dynamically generated. Put mid-capitalised strings here!
	 */
	private static final String[] USER_TEST_ATTRIBUTES = new String[] {
		"Login", "User", "userName", "UserName", "Utilisateur" };

	/**
	 * 
	 */
	public KnownLocations() {
		super();
	}

	/**
	 * {@inheritDoc}
	 */
	public int getPriority() {
		return 10;
	}

	/**
	 * {@inheritDoc}
	 */
	public Object guessUserFromSession(HttpSession httpSession) {
		Object user = null;

		for (int i = 0; i < USER_TEST_ATTRIBUTES.length; ++i) {
			Object obj = httpSession.getAttribute(USER_TEST_ATTRIBUTES[i]);
			if (null != obj) {
				user = obj;
				break;
			}
			obj = httpSession.getAttribute(USER_TEST_ATTRIBUTES[i].toLowerCase());
			if (null != obj) {
				user = obj;
				break;
			}
			obj = httpSession.getAttribute(USER_TEST_ATTRIBUTES[i].toUpperCase());
			if (null != obj) {
				user = obj;
				break;
			}
		}

		return user;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy