Tôi đang cố gắng bảo mật các điểm cuối của thiết bị truyền động khởi động mùa xuân. Tôi có bảo mật làm việc trên giao diện REST /api
REST của mình, nhưng cố gắng thêm bảo mật trên các điểm cuối được tích hợp sẵn dường như không hoạt động.Không thể bảo mật thiết bị đầu cuối thiết bị truyền động quản lý khởi động mùa xuân
Tôi đã thiết lập nhóm các thiết bị đầu cuối trong tôi application.properties
:
management.context-path=/management
Tôi có điều này trong Java Config tôi
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeRequests()
.antMatchers("/api/**").hasRole("READONLY")
.antMatchers("/management/**").hasRole("ADMIN");
SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurer = new XAuthTokenConfigurer(userDetailsServiceBean());
http.apply(securityConfigurer);
}
Khi tôi sử dụng trình duyệt của tôi để đi đến bất cứ điều gì dưới đây /api
, tôi lấy lại 403 như mong đợi. Khi đi đến/management/info
ví dụ, tôi thấy JSON được trả lại nơi tôi cũng mong chờ một 403.
Tôi cũng đã cố gắng này thêm vào tập tin application.properties
tôi:
management.security.role=ADMIN
Nhưng điều đó không giúp được gì.
Các DEBUG chương trình đầu ra:
2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource -
Adding web access control expression 'hasRole('ROLE_READONLY')', for Ant [pattern='/api/**']
2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource -
Adding web access control expression 'hasRole('ROLE_ADMIN')', for Ant [pattern='/management/**']
Và thì tại sao tôi cố gắng GET HTTP:
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/css/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/js/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/images/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/**/favicon.ico'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/management/info'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] FilterChainProxy - /management/info has an empty filter list
Hoàn toàn chính xác! Hai cái mà tôi đã thử là '/ info' và'/health' và cả hai dường như luôn sẵn sàng. Nếu tôi sử dụng '/ beans' chẳng hạn, tôi sẽ lấy lại 403 dự kiến. Bạn có thể thêm thông tin này [trong tài liệu] (http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-sensitive-endpoints)? –
Có ở đó: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-sensitive-endpoints, http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/# production-ready-endpoints. Nếu bạn muốn đề nghị làm rõ thêm, vui lòng làm. –
Thật vậy, có vẻ như tôi không chú ý đến cột 'Nhạy cảm' trong bảng. –