Tag: 角色

Spring Boot基于角色的认证

我有一个关于基于Spring Boot角色的身份validation的问题。 基本上,我想有用户和管理员,我想阻止用户访问管理资源。 所以我创建了一个SecurityConfig类: package test; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; @Configuration @EnableWebMvcSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser(“user1”).password(“password1”).roles(“USER, ADMIN”) .and() .withUser(“user2”).password(“password2”).roles(“USER”); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers(“/service/test”).access(“hasRole(‘USER’) or hasRole(‘ADMIN’)”) .antMatchers(“/service/admin”).access(“hasRole(‘ADMIN’)”); } } 这是我的小REST服务: package […]

Java EE服务器上的动态角色

我想在专用的应用程序中管理用户和角色。 例如,该应用程序的用户(“customerX boss”)可以创建新角色“customerX employee”。 如果员工访问Java EE应用程序服务器(GlassFish 3),他应该获得“customerX employee”角色。 这听起来很简单,但Java EE不支持它,因为组在启动时映射到角色,而应用程序中的角色是静态的。 在Java EE(6)环境中在运行时管理用户角色的最佳方法是什么?