2017-06-29 11 views
0

私の酷いアプリケーションには春のセキュリティが使用されています。ログイン後、従業員リストが表示されなければなりません。私は、そのページ内の任意の操作を実行する必要がある場合は、それも後のログインログインページにリダイレクトされる。ログインしても、すべてのURLがログインページ(春のセキュリティ)にリダイレクトされています

は、これは私のコントローラ

@RequestMapping(value="/login") 
    public String log(Model model){ 
     model.addAttribute("user", new User()); 
     return "login"; 
    } 

    @RequestMapping(value="/loginUser",method=RequestMethod.POST) 
    public String login(@ModelAttribute("user") User user,Model model){ 

     try{ 
     userService.login(user); 
     model.addAttribute("employee", new Employee()); 
     model.addAttribute("user", getPrincipal()); 
     return "redirect:/employees"; 
     }catch(Exception e){ 
      return "redirect:/accessDenied"; 
     } 
    } 

    @RequestMapping(value = "/employees", method = RequestMethod.GET) 
    public String listEmployee(Model model) { 
     model.addAttribute("employee", new Employee()); 
     model.addAttribute("user", getPrincipal()); 
     model.addAttribute("listEmployee", employeeService.listEmployee()); 
     return "employee"; 
    } 

    @RequestMapping(value= "/employee/add", method = RequestMethod.POST) 
    public String addEmployee(@ModelAttribute("employee") Employee emp,Model model){ 

     this.employeeService.addEditEmployee(emp); 
     model.addAttribute("user", getPrincipal()); 
     return "redirect:/"; 

    } 

    @RequestMapping("/delete/{id}") 
    public String removeEmployee(@PathVariable("id") int id,Model model){ 

     this.employeeService.deleteEmployee(id); 
     model.addAttribute("user", getPrincipal()); 
     return "redirect:/employees"; 
    } 

    @RequestMapping("/edit/{id}") 
    public String editEmployee(@PathVariable("id") int id, Model model){ 
     model.addAttribute("employee", employeeService.getEmployeeById(id)); 
     model.addAttribute("listEmployees",employeeService.listEmployee()); 
     model.addAttribute("user", getPrincipal()); 
     return "employee"; 
    } 

これで私の春のセキュリティ設定ファイル

<security:global-method-security secured-annotations="enabled"/> 
    <security:http auto-config="true" use-expressions="true"> 
     <security:intercept-url pattern="/" access="hasRole('ADMIN')"/> 
     <!-- <security:intercept-url pattern="/employees" access="hasRole('ADMIN')"/> --> 
     <security:form-login login-page="/login" login-processing-url="/login" 
          default-target-url="/employees" 
          authentication-failure-url="/login" /> 
    </security:http> 
    <security:authentication-manager > 
     <security:authentication-provider> 
      <security:jdbc-user-service authorities-by-username-query="" 
             users-by-username-query="select userName,password from user where userName=? AND password=?" 
             data-source-ref="dataSource"/> 
     </security:authentication-provider> 
    </security:authentication-manager> 
です

ここで私は必要なのは、一度私はすべての操作を実行する必要がログインします。私は、私がログインしたことを覚えておくのセッションを必要とする

+0

あなたはSpring Securityを使用する代わりにSpring Securityを利用しています。 Spring Securityが自分で作成するのではなくログインプロセスを処理するようにします。 –

+0

あなたの 'userService.login(user)は何をしますか? –

+0

パブリックユーザログイン(ユーザユーザ){ \t \tユーザー=(ユーザー)session.getCurrentSession()のcreateCriteria(User.class) \t \t \t \t .add(Restrictions.eq( "userNameに"、user.getUserName() )) \t \t \t \t .add(Restrictions.eq( "パスワード"、user.getPassword())) \t \t \t \t .uniqueResult(); \t \t返品ユーザー: –

答えて

2

はこの試してみてください。あなたは、コントローラのログインポストを処理している理由<security:intercept-url pattern="/**" access="hasRole('ADMIN')"/>

を!なぜあなたはログインに春のセキュリティを使用しないのですか?

関連する問題