001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
003: * JR Boyens <gnu-jrb[remove] at gmx dot net>
004: * Distributed under the terms of either:
005: * - the common development and distribution license (CDDL), v1.0; or
006: * - the GNU Lesser General Public License, v2.1 or later
007: * $Id: AuthenticationUtils.java 3643 2007-01-12 15:29:45Z gbevin $
008: */
009: package com.uwyn.rife.authentication;
010:
011: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.AuthenticatedElementNotFoundException;
012: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.NotAuthenticatedElementException;
013: import com.uwyn.rife.authentication.exceptions.SessionManagerException;
014: import com.uwyn.rife.engine.ElementInfo;
015: import com.uwyn.rife.engine.Site;
016:
017: /**
018: * This abstract class provides convenience shortcut methods to
019: * perform common operations with the authentication framework
020: *
021: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
022: * @version $Revision: 3643 $
023: * @since 1.4
024: */
025: public abstract class AuthenticationUtils {
026: /**
027: * Starts a new authentication session for a particular user and
028: * {@link com.uwyn.rife.authentication.elements.Authenticated Authenticated}
029: * element in a site.
030: *
031: * @param site the site in which the authenticated element is declared
032: * @param authElementId the absolute ID of the authenticated element that
033: * provides all the authentication related managers
034: * @param reference a reference element against which to resolve the id;
035: * or {@code null} if the provided id is absolute
036: * @param userId The id that uniquely identifies the user that is allowed
037: * to use this session.
038: * @param hostIp The ip address of the host from which the user accesses
039: * the application.
040: * @param remembered Indicates whether the session is started through
041: * remember me or from scratch.
042: * @return A {@code String} that uniquely identifies the
043: * authentication session that was just started.
044: * @exception AuthenticatedElementNotFoundException when the element ID
045: * couldn't be found in the site
046: * @exception NotAuthenticatedElementException when the element ID doesn't
047: * refer to an {@code Authenticated} element
048: * @exception SessionManagerException when an error occurred while startin
049: * the authentication session in a manager
050: * @since 1.4
051: */
052: public static String startAuthenticationSession(Site site,
053: String authElementId, ElementInfo reference, long userId,
054: String hostIp, boolean remembered)
055: throws AuthenticatedElementNotFoundException,
056: NotAuthenticatedElementException, SessionManagerException {
057: if (null == site)
058: throw new IllegalArgumentException("site can't be null");
059: if (null == authElementId)
060: throw new IllegalArgumentException(
061: "authElementId can't be null");
062: if (0 == authElementId.length())
063: throw new IllegalArgumentException(
064: "authElementId can't be empty");
065:
066: return SessionValidatorRetriever.getSessionValidator(site,
067: authElementId, reference).getSessionManager()
068: .startSession(userId, hostIp, remembered);
069: }
070:
071: /**
072: * Starts a new authentication session for a particular user and
073: * {@link com.uwyn.rife.authentication.elements.Authenticated Authenticated}
074: * element in a site.
075: *
076: * @param authElementInfo the {@code ElementInfo} of the authenticated
077: * element that provides all the authentication related managers
078: * @param userId The id that uniquely identifies the user that is allowed
079: * to use this session.
080: * @param hostIp The ip address of the host from which the user accesses
081: * the application.
082: * @param remembered Indicates whether the session is started through
083: * remember me or from scratch.
084: * @return A {@code String} that uniquely identifies the
085: * authentication session that was just started.
086: * @exception AuthenticatedElementNotFoundException when the element ID
087: * couldn't be found in the site
088: * @exception NotAuthenticatedElementException when the element ID doesn't
089: * refer to an {@code Authenticated} element
090: * @exception SessionManagerException when an error occurred while startin
091: * the authentication session in a manager
092: * @since 1.4
093: */
094: public static String startAuthenticationSession(
095: ElementInfo authElementInfo, long userId, String hostIp,
096: boolean remembered)
097: throws AuthenticatedElementNotFoundException,
098: NotAuthenticatedElementException, SessionManagerException {
099: if (null == authElementInfo)
100: throw new IllegalArgumentException(
101: "authElementInfo can't be null");
102:
103: return SessionValidatorRetriever.getSessionValidator(
104: authElementInfo).getSessionManager().startSession(
105: userId, hostIp, remembered);
106: }
107: }
|