我剛剛開始使用Spring Security進行編程,並且我編寫了系統,通過Hibernate將表中的用戶保存在表中。以Spring Security參考我寫的這個塊的代碼:如何在運行時向Spring Security添加新用戶
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.security.config.annotation.authentication.builders.*;
import org.springframework.security.config.annotation.web.configuration.*;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
而這完美的作品,但有一點 - 服務器啓動時用戶加載。我需要編寫方法RegisterUser(用戶用戶),在運行時將新用戶添加到Spring Security。這種方法應該只關注這個任務。我不知道如何開始實施此功能,所以感謝您的任何建議! ;)
OFC用戶有像登錄名,密碼,角色串等等等等領域......
與Spring MVC請不要發佈解決方案。該系統使用了Spring Web加速和Spring Security的提振4.0.x版
有人會幫忙嗎? –
那裏有Spring Security + Hibernate的例子,給它一個搜索。例如:http://www.mkyong.com/spring-security/spring-security-hibernate-annotation-example/ – holmis83
請問您是否發現了針對您的問題的解決方案,您可以發佈代碼嗎? –