-2

@PreAuthorize is not working in Spring Security 3.

This is my code snap.

 @PreAuthorize("hasRole('Admin') or hasRole('Student')")
 public void doSomething(){}

It is giving me weird error (refer attachment) enter image description here

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
  • Can you show the whole code of the class? – geoand Jul 02 '14 at 07:06
  • @geoand, I am not able to add whole code here, but I am sure that when I add only one line, server started to give me error. if I remove that line, Its working fine. – Vishal Zanzrukia Jul 02 '14 at 07:17
  • We need to know if the class or any of it's methods have been annotated when `@Transactional`, `@Scheduled` or some other Spring annotation – geoand Jul 02 '14 at 07:49
  • there is no methods annotated with `@Scheduled` in whole app but my service classes are annotated with `@Transactional`. but what is connection between @Transcational and @PreAuthorize ? – Vishal Zanzrukia Jul 02 '14 at 08:30
  • The issue is that in order to implement the functionality indicated by the annotations, Spring needs to create proxies. When multiple proxies are required, some things need to be configured correctly. Can you please show your Spring configuration? – geoand Jul 02 '14 at 08:34
  • is this link useful to me? http://stackoverflow.com/questions/8856995/order-of-spring-transactional-and-spring-security-preauthorize – Vishal Zanzrukia Jul 02 '14 at 09:07
  • 1
    It could be, yes. Have you tried it? The most helpful thing would be for you to post the Spring config – geoand Jul 02 '14 at 09:10
  • 1
    Thanks @geoand, I fixed issue by adding `` line in spring-security.xml – Vishal Zanzrukia Jul 02 '14 at 16:25

1 Answers1

0

for other interested people..

I fixed issue by adding

<aop:config proxy-target-class="true"></aop:config> 

line in spring-security.xml

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82