2015-08-23 97 views
2

我們正在使用activiti v5.18和spring boot。爲了調用activiti REST API,我們必須創建一個activiti用戶來傳遞基本認證。據我所知,activiti安全是基於spring啓動安全性,我們嘗試了兩種方法。如何禁用activiti REST HTTP

  1. 排除Activiti的春天啓動安全自動配置

    @EnableAutoConfiguration(exclude = {org.activiti.spring.boot.SecurityAutoConfiguration.class}) 
    
  2. 創建一個類來擴展Spring類的WebSecurityConfigurerAdapter),並設置 'security.basic.enabled =假' 在application.properties

    @Configuration 
    @EnableWebSecurity 
    @EnableGlobalMethodSecurity(prePostEnabled = true) 
    @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 
    
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
    
    // @formatter:off 
    http 
    .authorizeRequests() 
    .antMatchers(HttpMethod.GET, "/","/static/**", "/resources/**","/resources/public/**").permitAll() 
    .anyRequest().authenticated() 
    .and() 
    .formLogin() 
    .and() 
    .httpBasic().disable() 
    .requiresChannel().anyRequest().requiresSecure(); 
    // @formatter:on 
    } 
    } 
    

不幸的是,他們沒有禁用基本身份驗證,當我去頁面'http://localhost:8080/repository/deployments',瀏覽器彈出用戶登錄窗口。並在頁面上顯示錯誤消息

此應用程序沒有顯式映射/錯誤,因此您將此視爲後備。

有一個意外的錯誤(type = Unauthorized,status = 401)。 訪問此資源需要完全身份驗證

另外,我們有自己的REST服務,當客戶端調用我們的REST服務時,瀏覽器還要求輸入activiti REST用戶/密碼。

有什麼辦法可以禁用activiti REST HTTP基本認證嗎?

回答

2

你可以使用antMatchers爲某些類型的請求如禁用驗證HTTP-GET和/或HTTP-POST請求如下:

.antMatchers(HttpMethod.GET, "/**").permitAll() 

隨着他的指揮下,所有的HTTP-GET方法不需額外打到BasicAuthenticationFilter。對於我的UseCase,我必須以這種方式排除HTTP-Options請求。只需在activiti-webapp-rest2編輯org.activiti.rest.conf.SecurityConfiguration.java如下:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
    http 
    .authenticationProvider(authenticationProvider()) 
    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 
    .csrf().disable() 
    .authorizeRequests() 
    .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 
    .antMatchers(HttpMethod.GET, "/**").permitAll() 
    .antMatchers(HttpMethod.POST, "/**").permitAll() 
    .antMatchers(HttpMethod.PUT, "/**").permitAll() 
    .antMatchers(HttpMethod.DELETE, "/**").permitAll() 
     .anyRequest().authenticated() 
     .and() 
    .httpBasic(); 
    } 

之後,你必須重建Activiti的項目。重新部署war文件,之後,應禁用基本身份驗證。

+0

嗨,我想使用奶蛋烘餅和自定義身份驗證impl,而不是activiti中的基本身份驗證,所以我需要做你寫的東西,然後我在哪裏做我自己的身份驗證,並回答一個真實的驗證功能?我應該在哪裏放置斷點? – ilansch

+0

對於自定義認證,實現自定義認證過濾器public class CustomAuthenticationFilter extends AbstractAuthenticationProcessingFilter。在此過濾器中,您可以進行身份​​驗證。在的Spring Java配置,聲明你的過濾器作爲一個bean: \ @Bean \t公共CustomAuthenticationFilter customTokenAuthenticationFilter(){ \t \t回報新CustomAuthenticationFilter( 「/ **」);}; \ @Autowired CustomAuthenticationFilter customTokenAuthenticationFilter; 並使用.addFilterBefore(customTokenAuthenticationFilter,BasicAuthenticationFilter.class).httpBasic(); 將您的過濾器添加到鏈中。 – Ben

+0

嗨,spring conf文件在哪裏?當主持activiti休息? – ilansch

0

你可以使用這個類的配置與@Ben想法:

@Configuration 
@EnableWebSecurity 
@EnableWebMvcSecurity 
@Order(Ordered.HIGHEST_PRECEDENCE) 
public class CustomSecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Bean 
    @ConditionalOnMissingBean 
    public AuthenticationProvider authenticationProvider() { 
     return new BasicAuthenticationProvider(); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authenticationProvider(authenticationProvider()) 
       .csrf().disable() 
       .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 
       .authorizeRequests() 
       .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() 
       .antMatchers(HttpMethod.GET, "/**").permitAll() 
       .antMatchers(HttpMethod.POST, "/**").permitAll() 
       .antMatchers(HttpMethod.PUT, "/**").permitAll() 
       .antMatchers(HttpMethod.DELETE, "/**").permitAll() 
       .anyRequest().authenticated() 
       .and() 
       .httpBasic(); 
    } 
} 
2

這可能是月末來的OP,但這項工作,可能還是會幫助其他人。

@EnableAutoConfiguration(exclude = { 
org.activiti.spring.boot.RestApiAutoConfiguration.class, 
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class, 
org.activiti.spring.boot.SecurityAutoConfiguration.class, 
org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.class 
}) 
+0

https://forums.activiti.org/content/disable-activiti-spring-rest-api-basic-authentication – amorales

0

最近我還遇到了這個問題。我嘗試了幾個建議,花了很多時間,但我無法成功。但是有一個非常簡單的出路。如果一個犯規,而需要與自己的應用程序,這樣的整合它使用Activiti的休息,然後只取依賴

<dependency> 
<groupId>org.activiti</groupId> 
<artifactId>activiti-spring-boot-starter-rest-api</artifactId> 
<version>${activiti.version}</version> 
</dependency> 

出來。 希望它能幫助別人。沒有任何文件可以提到這一點。