swagger隐藏authentication参数
@Bean public Docket oauthApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("oauth") .apiInfo(metaData()) .ignoredParameterTypes(Authentication.class) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.ant("/oauth/**")) .build() .securitySchemes(Collections.singletonList(securitySchema())) .securityContexts(Collections.singletonList(securityContext())); }
Spring Security 中的自定义PreAuthorize 注解
controller: @NeedAdmin @GetMapping(path ="user", produces ="application/json") publicResponseEntity<User> getUser(@RequestParamString login){ ... } 自定义注解anno: @PreAuthorize("hasAuthority('Admin')") @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface NeedAdmin { }