开发者

Using custom annotations to generate biolerplate code

开发者 https://www.devze.com 2023-04-07 00:45 出处:网络
Folks, I am about to write a ton of J2EE/JAX-RS code where practically all public methods will do the following:

Folks, I am about to write a ton of J2EE/JAX-RS code where practically all public methods will do the following:

  • Look for the presence of a security token in the request header.
  • Call a utility to make sure the token is valid.
  • If not valid, return an error response (or inject a null token)
  • If valid, do some stuff, which might involve introspecting the token
  • In most cases, return an updated token in response headers.

I'd love to be able to use annotations to abstract out this piece. I am imagining something like the following on the met开发者_如何转开发hod:

@RequireToken( returnRenewed=true )
@POST
@Path( "/some/path" )
public Result myMethod( ... )
{
    @InjectedToken
    final Token securityToken;
    ...
}

Any pointers on how to proceed?


Have you considered using spring security for those actions? You might implement your own authentication filters.

If not spring security, maybe AOP and "before" or "around advice"s ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号