easytests.common.controllers.AbstractPersonalController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
c 0
b 0
f 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
getCurrentUserModel 0 10 ?
A getCurrentUserModel() 0 10 3
1
package easytests.common.controllers;
2
3
import easytests.core.models.UserModelInterface;
4
import easytests.core.services.UsersService;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.security.authentication.AnonymousAuthenticationToken;
7
import org.springframework.security.core.Authentication;
8
import org.springframework.security.core.context.SecurityContextHolder;
9
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.ModelAttribute;
11
12
13
/**
14
 * @author malinink
15
 */
16
@Controller
17
public class AbstractPersonalController {
18
    @Autowired
19
    protected UsersService usersService;
20
21
    private UserModelInterface userModel;
22
23
    private Boolean userModelFetched = false;
24
25
    @ModelAttribute("currentUserModel")
26
    public UserModelInterface getCurrentUserModel() {
27
        if (!this.userModelFetched) {
28
            final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
29
            if (!(authentication instanceof AnonymousAuthenticationToken)) {
30
                this.userModel = usersService.findByEmail(authentication.getName());
31
            }
32
            this.userModelFetched = true;
33
        }
34
        return this.userModel;
35
    }
36
}
37