Spring Roo 2.0.RC1 - Spring 安全提供程序默认并添加 Spring 安全配置

Spring Roo 2.0.RC1 - Spring Security Provider Default and add Spring Security Configuration

另一个问题。

我无法使用 Spring 安全提供程序 Springlets_Jpa 请参阅 ()

然后就是使用默认的Provider。 我有默认登录弹出窗口,默认用户和密码显示在 shell.

我不想让用户和角色 table 使用登录视图。 我用 Roo 添加了实体用户和角色。

我还没有 spring 安全配置。

entity jpa --class ~.model.User --plural Users --table USER --sequenceName USER_ID_SEQ --identifierStrategy AUTO --identifierColumn USER_ID --versionField version --versionType java.lang.Long --versionColumn VERSION --entityFormatExpression "User: #{firstname} #{lastname} (#{username})"
entity jpa --class ~.model.Role --plural Roles --table ROLE --sequenceName ROLE_ID_SEQ --identifierStrategy AUTO --identifierColumn ROLE_ID --versionField version --versionType java.lang.Long --versionColumn VERSION --entityFormatExpression "#{rolename}"

focus --class ~.model.User
field string --fieldName username --column USERNAME --notNull --unique --comment "Username des Nutzers" --regexp ^[a-zA-Z0-9_]{4,}$ 
field string --fieldName password --column PASSWORD --notNull --comment "Passwort des Nutzers" --regexp ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$
field string --fieldName firstname --column FIRST_NAME --notNull --comment "Vorname des Nutzers"
field string --fieldName lastname --column LAST_NAME --notNull  --comment "Nachname des Nutzers"
field string --fieldName email --column EMAIL --notNull --unique --comment "Email des Nutzers" --regexp ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
focus --class ~.model.Role
field enum --fieldName rolename --column ROLENAME --type ~.model.restricted.RoleType --notNull --comment "Rollentyp"
field set --fieldName userlst --type ~.model.User --mappedBy role --joinColumnName ROLE_ID --permitReservedWords --comment "Liste der User mit diesem Typ"

当我启动 webapp 时,我会创建角色和用户。我可以 select 创建用户视图中的角色。

现在我添加spring安全配置class(非常简单允许所有人无需登录)

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.authorizeRequests().antMatchers("/").permitAll();
    }

}

当我现在启动 web 应用程序并创建用户时,我无法 select 列表中的角色。 我收到警告

2017-03-30 09:12:55.088  WARN 6644 --- [nio-8082-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver :
Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWri
tableException: Could not write content: No converter found capable of converting from type [de.quin
tra.rechnungspruefung.model.Role] to type [java.lang.String] (through reference chain: io.springlets
.data.web.select2.Select2DataWithConversion["results"]); nested exception is com.fasterxml.jackson.d
atabind.JsonMappingException: No converter found capable of converting from type [de.quintra.rechnun
gspruefung.model.Role] to type [java.lang.String] (through reference chain: io.springlets.data.web.s
elect2.Select2DataWithConversion["results"])

现在在列表中显示角色。 怎么了?

几周前,我在 Spring 安全性中检测到一个问题,并在他们的存储库中创建了以下问题:

https://github.com/spring-projects/spring-security/issues/4202

似乎如果 @Configuration class 扩展了 WebSecurityConfigurerAdapter 抽象 class(就像在 Spring Roo 生成的代码中一样),某些组件是在 formatters 已在 Spring 上下文中注册之前尝试 @Autowired 一个 ConversionService 实例,因此 addFormatters 方法不包含任何格式化程序。

一个简单的解决方法可以解决您的问题,您将能够在您的项目中使用 Spring 安全性是 @Override 生成的 setContentNegotiationStrategy 方法=18=] class 不包括 @Autowired 注释。

下面的例子看一下如何正确重写这个方法。 (在此示例中,代码已注释)

https://github.com/jcagarcia/proofs/blob/master/spring-security-and-formatters/src/main/java/org/springframework/roo/petclinic/config/security/SecurityConfiguration.java#L54

如果这能解决您的问题,那么您 comment on the issue 说您也有同样的问题就太好了。

希望对您有所帮助,