package com.dev.swms.server.security.acegi;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.dev.energy.server.model.security.User;
import com.dev.energy.server.security.acegi.dao.AcegiUserCreateAfterInvocation;
import com.dev.energy.server.security.acegi.model.UserAdapter;

public class TelnetUserDetailConstructor implements
		AcegiUserCreateAfterInvocation {

	public UserAdapter generatorUserDetails(User user) {
		return new NewUserAdapter(user);
	}
	
	private class NewUserAdapter extends UserAdapter {

		public NewUserAdapter(User user) {
			super(user);
		}
		public String getPassword() {
	        return this.getUser().getStrExtend3();
	    }
		public boolean isCredentialsNonExpired(){
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			try {
				Date passwordExpiry = df.parse(this.getUser().getStrExtend4());
				return passwordExpiry.compareTo(new Date()) > 0;
			} catch (ParseException e) {
				e.printStackTrace();
			}

			return false;
	    }
		
	}

}
