Custom Authentication tip from cuba does not work in jmix

Hi, if you need to do something before token generation, you may try adding an interceptor to the authorization server endpoints.

Create the interceptor:

public class MyTokenEndpointInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //your code
    }
}

and the AuthorizationServerConfigurer:

@Component
public class MyAuthorizationServerConfigurer implements AuthorizationServerConfigurer {
    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.addInterceptor(new MyTokenEndpointInterceptor());
    }
}

In order to use the spring security oauth2 classes in your code, you need to explicitly add the dependency in the project build.gradle file, because jmix oauth2 module doesn’t transitively expose this dependency:

implementation 'org.springframework.security.oauth:spring-security-oauth2'