Announcement Announcement Module
Collapse
No announcement yet.
@After("execution(* doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @After("execution(* doesn't work

    Hi all,

    I'm now to spring, i'm trying to use AOP for my AuthenticationService

    this a part of my source code
    Code:
    public class AdviceLogger 
    {
    
    	@After("execution(* fr.portal.service.ServiceAuthentication.doUsernameAndPasswordMatch(..))")
    	public void logAfterIsUsernameAndPasswordMatch(JoinPoint joinPoint) 
    	{
    		System.out.println("logAfter() is running!");
    		System.out.println("Method name : " + joinPoint.getSignature().getName());
    		System.out.println("******");
    	}
    	
    }
    Code:
    package fr.portal.service;
    ..
    
    @Service
    public class ServiceAuthentication implements AuthenticationProvider
    {
    	
    ....
    	@Override
    	public Authentication authenticate(Authentication authentication) throws AuthenticationException 
    	{	
    	
    
    	    /**
    	     * Check if username/password match
    	     */
    	    if ( this.doUsernameAndPasswordMatch()) 
    		{
    	    	/**
    	    	 * Check if the account is enabled
    	    	 */
    			if ( this.isAccountEnabled() ) 
    			{
    				/**
    				 * Check if the subscription is still valid 
    				 */
    				if ( this.isSubscriptionValid() )
    				{
    					/**
    					 * Check if the account is not expired
    					 */
    					if( !this.isAccountExpired() )	
    					{
    						/**
    						 * Check if the account is not temporarily locked
    						 */
    						if ( !this.isTemporarilyLocked() )
    						{
    							...
    
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isSubscriptionValid()
    	{
    		return modelUser.getSubscriptionDateEnd() > currentDate.getTime();
    	}
    	
    	/**
    	 * 
    	 * @return boolean
    	 */
    	public boolean doUsernameAndPasswordMatch()
    	{
    		return modelUser != null;
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isAccountEnabled()
    	{
    		return modelUser.getEnabled() == 1;
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isAccountExpired()
    	{
    		return modelUser.getExpirationdate() < currentDate.getTime();
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isTemporarilyLocked()
    	{
    		return currentDate.getTime() - authUsers.get(currentIp).getLockingTime() < 60000 * Integer.parseInt(lockingtime);
    	}
    	
    }
    My conf is
    Code:
    ...
    <aop:aspectj-autoproxy />
    	<context:component-scan base-package="fr.portal.service" />
    	<context:component-scan base-package="fr.portal.dao.test" />
    	<context:component-scan base-package="fr.portal.advice" />

  • #2
    Please use the forum search as this question has been answered numerous times before, next to that it is also explained in the reference guide.

    In short, spring uses proxy based AOP and as such INTERNAL method calls aren't intercepted....

    Code:
    package fr.portal.service;
    ..
    
    @Service
    public class ServiceAuthentication implements AuthenticationProvider
    {
    	
    ....
    	@Override
    	public Authentication authenticate(Authentication authentication) throws AuthenticationException 
    	{	
    	
    
    	    /**
    	     * Check if username/password match
    	     */
    	    if ( this.doUsernameAndPasswordMatch()) <-- Internal Method Call 
    		{
    	    	/**
    	    	 * Check if the account is enabled
    	    	 */
    			if ( this.isAccountEnabled() ) 
    			{
    				/**
    				 * Check if the subscription is still valid 
    				 */
    				if ( this.isSubscriptionValid() )
    				{
    					/**
    					 * Check if the account is not expired
    					 */
    					if( !this.isAccountExpired() )	
    					{
    						/**
    						 * Check if the account is not temporarily locked
    						 */
    						if ( !this.isTemporarilyLocked() )
    						{
    							...
    
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isSubscriptionValid()
    	{
    		return modelUser.getSubscriptionDateEnd() > currentDate.getTime();
    	}
    	
    	/**
    	 * 
    	 * @return boolean
    	 */
    	public boolean doUsernameAndPasswordMatch()
    	{
    		return modelUser != null;
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isAccountEnabled()
    	{
    		return modelUser.getEnabled() == 1;
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isAccountExpired()
    	{
    		return modelUser.getExpirationdate() < currentDate.getTime();
    	}
    	
    	/**
    	 * 
    	 * @return
    	 */
    	public boolean isTemporarilyLocked()
    	{
    		return currentDate.getTime() - authUsers.get(currentIp).getLockingTime() < 60000 * Integer.parseInt(lockingtime);
    	}
    	
    }

    Comment


    • #3
      Thanks for your reply, so in brief i have to create an other class that has doUsernameAndPasswordMatch as method and called from my ServiceAuthentication

      Comment

      Working...
      X