我有一個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. 的Java + Vaadin + Spring Security的
- 2. Thymeleaf Swich with Spring Security
- 3. 打造遊戲! project with maven
- 4. maven with spring mvc
- 5. JAXB Header security with Spring-WS
- 6. Spring Security with OpenId簽入isAccountNonLocked
- 7. 用於Vaadin的Spring Security的Java配置
- 8. Spring Security OAuth with JWK示例
- 9. Spring Security with multi-factor authentication
- 10. Spring Boot with Jersey and Spring Security OAuth2
- 11. Spring Security與OpenID和數據庫集成
- 12. 更改Vaadin/Spring-Boot/Maven中的CSS
- 13. Grails,Vaadin和Spring Security Plugin在一起
- 14. Spring Vaadin主題
- 15. Spring數據jpa + Vaadin Bean配置
- 16. 使用Vaadin使用Spring Security 403 CSRF令牌錯誤
- 17. 多個數據庫Schema with Spring + Hibernate + JPA
- 18. Spring Security中的NoSuchBeanDefinitionException
- 19. Spring Security with XML configuration does not authenticate user
- 20. Saml with spring security - 檢索組憑證
- 21. GAE上的Spring Boot + Spring Data with CloudSql - 數據庫連接
- 22. java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication with maven-jar-plugin
- 23. 集成Spring Boot與Spring Security
- 24. Spring Security OAuth Maven編譯失敗
- 25. Spring MVC Project
- 26. Spring Security - CouchDB
- 27. Spring Security的LDAP
- 28. Spring Security - 具有默認權限的數據庫授權?
- 29. Spring Security Grails插件使用現有的數據庫模式?
- 30. Spring 4 with Hibernate
我有一個應用程序的工作示例使用Vaadin + Spring Boot + Spring Security,但不幸的是這個例子沒有任何文檔。但是,也許你可以從你的任務的代碼中獲得一些啓發:https://github.com/rolandkrueger/vaadin-by-example/tree/master/en/architecture/SpringBootSecurity –
謝謝,我將會看到它 –
請RolandKrüger,這個例子中數據庫的配置在哪裏? –