Spring Roo 2.0.RC1 - Spring Security Provider 默认并添加 Spring



另一个问题。

我不能使用 Spring Security Provider Springlets_Jpa看到(Spring Roo 2.0.RC1:使用 Mysql DB with springlet 身份验证)

然后是使用默认提供程序。 我有默认登录弹出窗口,默认用户名和密码显示在 shell 中。

我不想让用户和角色表使用登录视图。 我已经添加了具有Roo的实体用户和角色。

我还没有弹簧安全配置。

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时,我acbb创建了角色和用户。我可以在创建用户视图中选择角色。

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

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 应用程序并创建用户时,我无法从列表中选择角色。 我收到警告

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 Security 中检测到一个问题,并在他们的存储库中创建了以下问题:

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

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

一个简单的解决方法可以解决您的问题,并且您将能够在项目中使用 Spring 安全性,方法是在生成的SecurityConfiguration类中@OverridesetContentNegotiationStrategy方法,而不包含@Autowired注释。

下面的示例查看如何正确重写此方法。(在此示例中,代码被注释)

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

如果这解决了您的问题,那么您对该问题发表评论说您有同样的问题会很棒。

希望对您有所帮助,

相关内容

最新更新