• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generated Cookie

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

I would like to know wich are the cookie strategies generation ? I've read here about "System.nanoTime()" but....there are another options ?
Regards.
 
Roel De Nijs
Sheriff
Posts: 10430
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

I used System.nanoTime(), but of course you can use the Random class and use the nextLong() method. Or you can use both and multiply both results with each other. But i think System.nanoTime() should do the job. You can always add something to your choices.txt that generation cookie logic can be refined (extended) in a future release...

Kind regards,
Roel
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Fernando!

You may also want to take a look at the SecureRandom class.
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel and Roberto.

Another question about it: What should I do when someone try lock an ID that already looked ?? My inteface only throw RecordNotFoundException ? Should I throw one database runtime exception ? What did you do Roel ??
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Fernando!

What should I do when someone try lock an ID that already looked ??


Ah... that's where the locking mechanism comes in! This is what I have in my instructions.html file:

Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.


So... the client trying to lock a record that is already locked should wait until that particular record is available. After getting its lock, then the update/delete should proceed normaly.
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OHH MY GODDD !!! This is exactly what my assignment said !!! Wowwwwwwwww......sorry
 
Roel De Nijs
Sheriff
Posts: 10430
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

I would certainly not throw any exception, otherwise you will fail automatically, like Laura Pecoraro. Here you can find some information about her mistake and how you can/should deal with it.

Kind regards,
Roel
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Roel.... I'm sure that I wont comit the Laura mistake.
About SecurityException in unlock method. Can I throw it if passed a recordNumber that wasn't locked or if passed a wrong cookie value ?
 
Roel De Nijs
Sheriff
Posts: 10430
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

You can certainly throw it if a wrong cookie value is passed, because I believe that is exactly why the SecurityException exists. But a record that is not locked, is a subtle difference.
In my assignment I had no SecurityException, so I throw in both situations an IllegalStateException.

In this thread someone asked the same question like you.

Kind regards,
Roel
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks

I'm writting choice.txt and I need put 'why' I choose System.nanoTime() to generate locke cookie.
I'm actually did cause you guys suggest for me.... And it really work !
Could you help me please ?
Regards.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just say that this approach is secure enough to distinguish one client from the others.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic