我有一个vaadin maven项目,我在spring security中集成,所以我能够看到spring security的默认登录形式。 现在我想从postgres数据库获得用户请帮助我吗?你有任何tuto或书吗?感谢“SA很多Spring Security with vaadin maven project中的数据库
回答
作为例子(尊重罗兰Krügers例子)春季启动应用+ SpringSecurity + Vaadin4Spring#Hibernate,就必须在application.properties定义以下属性:
# DATASOURCE
spring.datasource.url=jdbc:postgresql://localhost/myDB
spring.datasource.username=myuser
spring.datasource.password=mypwd
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.xa.data-source-class-name=org.postgresql.xa.PGXADataSource
spring.datasource.pinGlobalTxToPhysicalConnection="true"
# one transaction manager via view
spring.jpa.open-in-view=true
# for mapping models and attributes to table names and column names
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jta.default-transaction-timeout=2000
使用application.properties在您的应用程序下面的注释添加到您的主类:
@PropertySources({
@PropertySource({"classpath:application.properties"})
})
现在,用户的实体可以是这样的:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@Entity
@Table(name = "USER")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", nullable = false, updatable = false)
private Long id;
@Column(name = "LAST_NAME", nullable = false)
private String lastName;
@Column(name = "FIRST_NAME", nullable = false)
private String firstName;
@Column(name = "LOGGED_IN")
private boolean loggedIn;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public boolean isLoggedIn() {
return loggedIn;
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}
}
之后,你必须定义对Hibernate的存储库接口:
/**
*Spring auto repository for database access of User objects.
**/
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findOneByName(String userName);
}
现在你可以做这样的事情在你的登录方法:
...
vaadinSecurity.login(userName.getValue(), passwordField.getValue());
Optional<User> ouser = userRepository.findOneByName(userName);
if (ouser.isPresent()) {
User user = ouser.get();
user.setLoggedIn(true);
}
...
谢谢亚历山大,但请问vaadinSecurity呢?它是什么?谢谢 –
'VaadinSecurity'来自vaadin4spring知识库[link](https://github.com/peholmst/vaadin4spring)。这提供了一些不错的服务,如I18N,安全和其他。看看[链接](https://vaadin.com/web/petter/home/-/blogs/experimenting-with-vaadin-spring-and-serialization?_33_redirect=https%3A%2F%2Fvaadin.com% 2Fweb%2Fpetter%2Fhome%3Fp_p_id%3D33%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-1%26p_p_col_pos%3D2%26p_p_col_count%3D3)设计如何使用vaadin4spring。里面还有一些样品。 –
我试图用vaadin和spring启动配置spring安全性,我使用SecurityConfig.java而不是xml文件我的问题现在我想创建我的自定义登录视图,但我不能,现在我仍然拥有默认的Spring登录形式你有什么想法? –
- 1. Bulid maven project with profile
- 2. 的Java + Vaadin + Spring Security的
- 3. Thymeleaf Swich with Spring Security
- 4. Spring Security与Project Reactor集成
- 5. Spring Security + Vaadin Session No VaadinSession
- 6. 打造游戏! project with maven
- 7. maven with spring mvc
- 8. Spring Security with Legacy Single Sign-On
- 9. JAXB Header security with Spring-WS
- 10. Vaadin maven-project通常会停止构建
- 11. Spring Security with AcceptHeaderLocaleResolver和i18n
- 12. Spring Security with OpenId签入isAccountNonLocked
- 13. 用于Vaadin的Spring Security的Java配置
- 14. Spring Security OAuth with JWK示例
- 15. Spring Security with multi-factor authentication
- 16. Spring Boot - Angularjs $ stateProvider with Security
- 17. Spring Boot with Jersey and Spring Security OAuth2
- 18. Spring Security与OpenID和数据库集成
- 19. 更改Vaadin/Spring-Boot/Maven中的CSS
- 20. Grails,Vaadin和Spring Security Plugin在一起
- 21. 将Spring Security与Vaadin 7集成
- 22. Spring Vaadin主题
- 23. Spring Security with JDBC Authentication - No AuthenticationProvider found
- 24. Spring数据jpa + Vaadin Bean配置
- 25. 使用Vaadin使用Spring Security 403 CSRF令牌错误
- 26. 多个数据库Schema with Spring + Hibernate + JPA
- 27. 来自Eclipse,maven,spring project的jar
- 28. Spring Security中的NoSuchBeanDefinitionException
- 29. Spring Security with XML configuration does not authenticate user
- 30. 错误404 Spring Security 4.0 with primefaces
我有一个应用程序的工作示例使用Vaadin + Spring Boot + Spring Security,但不幸的是这个例子没有任何文档。但是,也许你可以从你的任务的代码中获得一些启发:https://github.com/rolandkrueger/vaadin-by-example/tree/master/en/architecture/SpringBootSecurity –
谢谢,我将会看到它 –
请RolandKrüger,这个例子中数据库的配置在哪里? –