简体   繁体   English

弹簧引导弹簧安全angularjs

[英]spring-boot spring security angularjs

I'm a newbie to the spring world. 我是春季世界的新手。 I need to create a spring boot - angularjs application with some CRUD operations. 我需要创建一个带有一些CRUD操作的spring boot-angularjs应用程序。

The clients need LDAP and local JDBC authentication mechanisms. 客户端需要LDAP和本地JDBC身份验证机制。

They need an authorization mechanism which is common for both sets of users. 他们需要两种用户都通用的授权机制。

The users should be restricted from some pages based on their roles. 应根据用户的角色限制用户访问某些页面。 And separate permissions(Create, Update, Delete) sets needed to be applied to each user 并且需要将单独的权限(创建,更新,删除)设置应用于每个用户

And the roles should be created by the Admin user. 并且角色应该由管理员用户创建。

so how can I implement the page-wise authorization which would be decided by the admin that who (which role) can access which page? 那么我如何实现按页面授权,这将由管理员决定谁(哪个角色)可以访问哪个页面?

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/", "/home").permitAll().antMatchers("/admin").hasRole("ADMIN")
                .anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout()
                .permitAll();
        http.exceptionHandling().accessDeniedPage("/403");
    }

should I specify each role-page combination in the config? 我应该在配置中指定每个角色页面组合吗? Is there any way to dynamically change pages and roles, as the roles may get added later. 有什么方法可以动态更改页面和角色,因为以后可能会添加角色。

You can use spring mvc and Secured annotation 您可以使用spring mvc和Secured批注

@Controller
public class MainController extends BaseController  {

    @Secured("ROLE_ADMIN")
    @RequestMapping("/")
    String home(Model model) {
        return "home";
    }

} }

home page will be /resources/templates/home.ftl or jsp as you preferred. 根据您的喜好,主页将是/resources/templates/home.ftl或jsp。 If User is not admin then it will redirect to error page. 如果用户不是管理员,则它将重定向到错误页面。

If you want you can check permissions manually and send redirect to another page. 如果需要,您可以手动检查权限,然后将重定向发送到另一个页面。

PS : You need to add @EnableGlobalMethodSecurity(securedEnabled = true) to Spring boot Configuration class in order to Secured annotation work. PS:您需要将@EnableGlobalMethodSecurity(securedEnabled = true)添加到Spring boot Configuration类中,以便进行安全注释工作。

@EnableAutoConfiguration
@ComponentScan
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class Application {

   public static void main(String[] args) throws Exception {
       SpringApplication.run(Application.class, args);
   }

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM