Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle securityException in Service layer

 
Colin Duggan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Urlybird DB interface i have an unlock method which throws a RecordNotFoundExecption and SecurityException.

Im wondering how should i handle the SecurityException in my service layer? If the exception is thrown in the first place it means that someone is violating the rules of the api. There doesnt seem to be any point bubling this up to the UI layer?

Should i just override the DB interface unlock method and replace the SecurityException with a RuntimeException or do i need to handle this?? Thanks

 
Roel De Nijs
Sheriff
Posts: 10594
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Colin Duggan wrote:There doesnt seem to be any point bubling this up to the UI layer?

You should not handle this exception, because it indicates wrong api usage.


Colin Duggan wrote:Should i just override the DB interface unlock method and replace the SecurityException with a RuntimeException or do i need to handle this??

If you don't want to fail automatically you should not make any changes to the interface you got. In my opinion the SecurityException should be a runtime exception, not a checked exception. Using the search engine of this forum, you'll can find many threads about this topic, e.g. this one.
 
Colin Duggan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Roel. Had a quick look at some of the other posts but alot of varying answers. (Thats my excuse anyway )

when i say override - i have a custom interface which extends the one supplied by Sun. I think most people have taken this approach. Then in my custom interface i override the unlock method signature
 
Roel De Nijs
Sheriff
Posts: 10594
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Colin Duggan wrote:when i say override - i have a custom interface which extends the one supplied by Sun. I think most people have taken this approach. Then in my custom interface i override the unlock method signature

As long as you provide a valid override, you don't have to worry (I followed same approach), but if it's declared as a runtime exception no need to override these methods
 
Colin Duggan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was concerned that because the SecurityException appeared in the throws clause of the Sun interface that it had to be declared as checked but declaring as unchecked makes alot more sense.


The other reason I override the method is because i dont want to throw RNFE so my override just looks like this.




 
Roel De Nijs
Sheriff
Posts: 10594
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would assume you followed same approach for update and delete methods?
 
Colin Duggan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, only Runtime exceptions thrown in those methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic