/**
 * Copyright (C) 2012 Esup Portail http://www.esup-portail.org
 * Copyright (C) 2012 UNR RUNN http://www.unr-runn.fr
 * Copyright (C) 2012 RECIA http://www.recia.fr
 * @Author (C) 2012 Vincent Bonamy <Vincent.Bonamy@univ-rouen.fr>
 * @Contributor (C) 2012 Jean-Pierre Tran <Jean-Pierre.Tran@univ-rouen.fr>
 * @Contributor (C) 2012 Julien Marchal <Julien.Marchal@univ-nancy2.fr>
 * @Contributor (C) 2012 Julien Gribonvald <Julien.Gribonvald@recia.fr>
 * @Contributor (C) 2012 David Clarke <david.clarke@anu.edu.au>
 * @Contributor (C) 2012 BULL http://www.bull.fr
 * @Contributor (C) 2012 Pierre Bouvret <pierre.bouvret@u-bordeaux4.fr>
 * @Contributor (C) 2012 Franck Bordinat <franck.bordinat@univ-jfc.fr>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.esupportail.portlet.filemanager.services.auth;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.esupportail.portlet.filemanager.beans.SharedUserPortletParameters;
import org.esupportail.portlet.filemanager.beans.UserPassword;

public class UserPasswordAuthenticatorService implements UserAuthenticatorService {

	protected static final Log log = LogFactory.getLog(UserPasswordAuthenticatorService.class);

	protected UserPassword userPassword = new UserPassword();

	protected String userInfo4Username;
	
	public void setUsername(String username) {
		userPassword.setUsername(username);
	}
	
	public void setPassword(String password) {
		userPassword.setPassword(password);
	}
	
	public void setDomain(String domain) {
		userPassword.setDomain(domain);
	}

	/**
	 * To set a default username retrieving from user uPortal attributes
	 * @param userInfo4Username
	 */
	public void setUserInfo4Username(String userInfo4Username) {
		this.userInfo4Username = userInfo4Username;
	}

	public void initialize(SharedUserPortletParameters userParameters) {
		Map userInfos = userParameters.getUserInfos();
		if(this.getUserPassword(userParameters).getUsername() == null && 
				userInfo4Username != null && 
				userInfos != null && 
				userInfos.containsKey(userInfo4Username)) {
			this.setUsername((String)userInfos.get(userInfo4Username));
		}
	}
	
	public UserPassword getUserPassword(SharedUserPortletParameters userParameters) {
		return userPassword;
	}

}

@@ -1893,24 +1893,65 @@
 ername;%0D%0A%09%0D%0A
+%09protected String userInfo4Password;%0D%0A%09%0D%0A
 %09public void
@@ -1979,24 +1979,24 @@
 sername) %7B%0D%0A
-
 %09%09userPasswo
@@ -2424,24 +2424,254 @@
 ername;%0D%0A%09%7D%0D
+%0A%09%0D%0A%09/**%0D%0A%09 * To set a default password retrieving from user uPortal attributes%0D%0A%09 * @param userInfo4Password%0D%0A%09 */%0D%0A%09public void setUserInfo4Password(String userInfo4Password) %7B%0D%0A%09%09this.userInfo4Password = userInfo4Password;%0D%0A%09%7D%0D
 %0A%0D%0A%09public v
@@ -2962,16 +2962,16 @@
 me)) %7B%0D%0A
-
 %09%09%09this.
@@ -3031,16 +3031,265 @@
 ;%0D%0A%09%09%7D%0D%0A
+%09%09if(this.getUserPassword(userParameters).getPassword() == null && %0D%0A%09%09%09%09userInfo4Password != null && %0D%0A%09%09%09%09userInfos != null && %0D%0A%09%09%09%09userInfos.containsKey(userInfo4Password)) %7B%0D%0A%09%09%09this.setPassword((String)userInfos.get(userInfo4Password));%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%09%0D%0A%09

add userInfo4Password in UserPasswordAuthenticatorService to set a default password retrieving from user uPortal attributes