001/*
002 * Copyright (c) 2003-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: tao $'
006 * '$Date: 2011-03-31 18:37:56 +0000 (Thu, 31 Mar 2011) $' 
007 * '$Revision: 27403 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.authentication;
031
032/**
033 * AuthenticationService is responsible for contact the GAMA service and get
034 * back the credential for the user
035 * 
036 * @author Zhijie Guan guan@sdsc.edu
037 * 
038 */
039
040public abstract class AuthenticationService {
041        protected String serviceURL; // The service URL
042        protected String operationName; // The service operation name
043        protected String userName; // The username
044        protected String password; // The user password
045        protected String credential; // The user's credential if this service
046        protected AuthenticationListener authListener = null;
047        // if this service supports credentials
048
049        /**
050         * @param operationName
051         *            The operationName to set.
052         */
053        public void setOperationName(String operationName) {
054                this.operationName = operationName;
055        }
056
057        /**
058         * @param password
059         *            The password to set.
060         */
061        public void setPassword(String password) {
062                this.password = password;
063        }
064
065        /**
066         * @param serviceURL
067         *            The serviceURL to set.
068         */
069        public void setServiceURL(String serviceURL) {
070                this.serviceURL = serviceURL;
071        }
072
073        /**
074         * @param userName
075         *            The userName to set.
076         */
077        public void setUserName(String userName) {
078                this.userName = userName;
079        }
080
081        /**
082         * 
083         * Note, currently unused, and authenticate(null) will cause NPE.
084         * 
085         * Function: to check if the user can get authentication correctly. Note:
086         * need to talk with GAMA group to see what will be returned if something is
087         * wrong
088         * 
089         * @return True/False to state if the user get authenticated or not
090         */
091        public boolean isAuthenticated() throws AuthenticationException {
092                //FIXME using null here causes NPE:
093                authenticate(null); // Try to get authentication
094                if (credential == null) {
095                        return false;
096                }
097                return true;
098        }
099
100        /**
101         * @return Credential to the user
102         */
103        public String getCredential() {
104                return credential;
105        }
106        
107        /**
108   * Set the authentication listener
109   * @param listener
110   */
111  public void setAuthenticationListener(AuthenticationListener listener) {
112    authListener = listener;
113  }
114
115        /**
116         * Authenticate a user
117         */
118        public abstract ProxyEntity authenticate(Domain domain)
119                        throws AuthenticationException;
120
121        /**
122         * Unauthenticate a user
123         */
124        public abstract void unauthenticate(ProxyEntity proxy)
125                        throws AuthenticationException;
126
127}