Hello,

Thanks for the nudge in the right direction.
 
I created the service and I was wondering if you could have a look at how I
created it to be sure I've done it right(Everything seems to work fine but
it's my first service and I want to be sure it's done right):
 
Steps in reverse order basically:
 
Added to page:
@Inject
 private FailedLoginPrevention flp;
 
Activate it:
binder.bind(FailedLoginPrevention.class, FailedLoginPreventionImpl.class);
 
Interface:
public interface FailedLoginPrevention {
 
 int checkIP(String IP);
}
 
Implementation:
public class FailedLoginPreventionImpl implements FailedLoginPrevention {
public static Map<String, FailedLoginPreventionHelper> ipmap = new
HashMap<String, FailedLoginPreventionHelper>();  @Override  public
synchronized int checkIP(String IP) {
  if (FailedLoginPreventionImpl.ipmap.containsKey(IP)) {
   // IP is there check last failed login
   FailedLoginPreventionHelper flph = FailedLoginPreventionImpl.ipmap
     .remove(IP);
   Calendar now = Calendar.getInstance();
   if ((now.getTimeInMillis() - flph.getLastcheck().getTimeInMillis()) >
(1000 * 60 * 60 * 5)) {// 5
    //last failed login was more than 5 hours ago, reset the ip's time
// hours
    flph.setTime(0);
   } else {
    flph.setTime(flph.getTime() * 2);
   }
   flph.setLastcheck(now);
   FailedLoginPreventionImpl.ipmap.put(IP, flph);
   return flph.getTime();
  }
  FailedLoginPreventionImpl.ipmap.put(IP, new
FailedLoginPreventionHelper());
  return 0;
 }
}

Helper Class:
public class FailedLoginPreventionHelper {
 
 private int _time = 0;
 private Calendar _lastcheck = Calendar.getInstance();
 
 
 public int getTime() {
  return _time;
 }
 public void setTime(int time) {
  this._time = time;
 }
 public Calendar getLastcheck() {
  return _lastcheck;
 }
 public void setLastcheck(Calendar lastcheck) {
  this._lastcheck = lastcheck;
 }
}

Thanks,
--James

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiag...@gmail.com] 
Sent: February-11-09 9:18 AM
To: Tapestry users
Subject: Re: IoC question - introducing a time delay in an ASO

On Wed, Feb 11, 2009 at 11:16 AM, Ulrich Stärk <u...@spielviel.de> wrote:
> Something like a singleton tapestry service with an access-synchronized
map
> inside maybe?

That's what I'd do.
James: sorry for mistaking your message as someone else's. :)

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to