Prevent Method call without Exception using @PreAuthorize Annotation
package com.myapp;
public class MyMethodSecurityInterceptor extends MethodSecurityInterceptor {
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
Object result = null;
try {
InterceptorStatusToken token = super.beforeInvocation(mi);
} catch (AccessDeniedException e) {
(to be continue...)
(continue)
/ / access denied - do not invoke the method and return null
return null;
}
/ / access granted - proceed with the method invocation
try {
result = mi.proceed();
} finally {
result = super.afterInvocation(token, result);
}
return result;
}
}
<aop:config >
<!-- Intercept all relevant methods -- >
<aop:pointcut id="myMethods"
expression='execution(* com.myapp.myService+.*(..))'/ >
<aop:advisor advice-ref="mySecurityInterce ptor" pointcut-ref="myMethods"/ >
</ aop:config >
<!-- Configure custom security interceptor -- >
<bean id="mySecurityInterceptor"
class="com.myapp.MyMethodSecu rityInterceptor" >
<property name="securityMetadataSource" >
<bean class="org.springframework.se curity.access.prepost.PrePostA nnotationSecurityMetadataSourc e" >
<constructor-arg >
<bean class="org.springframework.se curity.access.expression.metho d.ExpressionBasedAnnotationAtt ributeFactory" >
<constructor-arg >
<bean class="org.springframework.se curity.access.expression.metho d.DefaultMethodSecurityExpress ionHandler"/ >
</ constructor-arg >
</ bean >
</ constructor-arg >
</ bean >
</ property >
<property name="validateConfigAttribute s" value="false"/ >
<property name="accessDecisionManager" ref="accessDecisionManager"/ >
<property name="authenticationManager" ref="authenticationManager"/ >
</ bean >
<!-- Configure AccessDecisionManager -- >
<bean id="accessDecisionManager" class="org.springframework.se curity.access.vote.Affirmative Based" >
<property name="decisionVoters" >
<list >
<bean class="org.springframework.se curity.access.prepost.PreInvoc ationAuthorizationAdviceVoter" >
<constructor-arg >
<bean class="org.springframework.se curity.access.expression.metho d.ExpressionBasedPreInvocation Advice"/ >
</ constructor-arg >
</ bean >
</ list >
</ property >
</ bean >
<!-- Configure AuthenticationManager as you wish -- >
<!-- ............................. .............. -- >
@Aspect
public class AccessDeniedHaltPreventionAdv ice {
private final Log logger = LogFactory.getLog(AccessDenie dHaltPrevention.class);
@Around("execution(@org.spring framework.security.access.prep ost.PreAuthorize * *(..))")
public Object preventAccessDeniedHalting(Pr oceedingJoinPoint pjp) throws Throwable{
Object retVal = null;
try{
retVal = pjp.proceed();
}catch(AccessDeniedException ade){
logger.debug("** Access Denied ** ");
}catch(Throwable t){
throw t;
}
return retVal;
}
<aop:aspectj-autoproxy/ >
public class SkipMethodCallAccessDecisionM anager extends AffirmativeBased {
@Override
public void decide(Authentication authentication, Object object, Collection <ConfigAttribute > configAttributes){
try{
super.decide(authentication, object, configAttributes);
}catch(AccessDeniedException adex){
logger.debug("Access Denied on:" + object);
}
}
}
<sec:global-method-security pre-post-annotations="enabled " access-decision-manager-ref=" skipMethodCallAccessDecisionMa nager "/ >
<bean id="skipMethodCallAccessDecis ionManager" class="com.application.auth.v ote.SkipMethodCallAccessDecisi onManager " >
<property name="decisionVoters" >
<list >
<bean class="org.springframework.se curity.access.prepost.PreInvoc ationAuthorizationAdviceVoter" >
<constructor-arg ref="expressionBasedPreInvoca tionAdvice"/ >
</ bean >
<!-- Insert RoleVoter if required -- >
<bean class="org.springframework.se curity.access.vote.Authenticat edVoter"/ >
</ list >
</ property >
</ bean >
<bean id="expressionBasedPreInvocat ionAdvice" class="org.springframework.se curity.access.expression.metho d.ExpressionBasedPreInvocation Advice" >
<property name="expressionHandler" ref="expressionHandler"/ >
</ bean >
package com.myapp;
public class MyMethodSecurityInterceptor extends MethodSecurityInterceptor {
(to be continue...)
}
<aop:config
</
<!-- Configure custom security interceptor --
<bean id="mySecurityInterceptor"
</
<!-- Configure AccessDecisionManager --
<bean id="accessDecisionManager" class="org.springframework.se
</
<!-- Configure AuthenticationManager as you wish --
<!-- .............................
@Aspect
public class AccessDeniedHaltPreventionAdv
private final Log logger = LogFactory.getLog(AccessDenie
@Around("execution(@org.spring
public Object preventAccessDeniedHalting(Pr
}
<aop:aspectj-autoproxy/
public class SkipMethodCallAccessDecisionM
}
<sec:global-method-security pre-post-annotations="enabled
<bean id="skipMethodCallAccessDecis
</
<bean id="expressionBasedPreInvocat
</
Date: 2012-07-06 14:40:03 and last modified: 2012-07-06 14:40:03
Relate posts:
- microsoft office access 2007
- 159834 bianca beauchamp all access avi
- ms access 2003 rar
- teen sandra model nude zip
- students consultant
- 18 wos pttm cracked exe
- access vba programming rar
- microsoft office access 2003
- access boss
- download bokep 2 mb
- bean part1 rar
- youtube video grabber 1 9 6 rar
- instructions how to plant bean
- aquaveo sms v10 1 11 x64 bean rar
- sycode point cloud v1 0 nope rar
- axure rp pro v5 6 0 2097 bean rar
- bean 1997
- mr bean download rapidshare
- [bean,bag] $(document).ready(function(){ $('.active-bean-bag ul li.bean
- [bean,property] <!--UNTUK REPORT --> <bean id="jasperViewResolver" class