1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.impl.action.common;
20
21 import org.springframework.security.core.Authentication;
22 import org.springframework.security.core.context.SecurityContext;
23 import org.springframework.security.core.context.SecurityContextHolder;
24
25 import com.hack23.cia.model.internal.application.user.impl.UserAccount;
26 import com.hack23.cia.service.api.action.common.ServiceRequest;
27 import com.hack23.cia.service.api.action.common.ServiceResponse;
28
29
30
31
32
33
34
35
36
37 public abstract class AbstractBusinessServiceImpl<T extends ServiceRequest, V extends ServiceResponse>
38 implements BusinessService<T, V> {
39
40
41 private final Class<T> clazz;
42
43
44
45
46
47
48
49 public AbstractBusinessServiceImpl(final Class<T> clazz) {
50 this.clazz = clazz;
51 }
52
53 @Override
54 public final Class<? extends ServiceRequest> getSupportedService() {
55 return clazz;
56 }
57
58
59
60
61
62
63 protected final UserAccount getUserAccountFromSecurityContext() {
64 final SecurityContext context = SecurityContextHolder.getContext();
65 if (context != null) {
66 final Authentication authentication = context.getAuthentication();
67 if (authentication != null) {
68 final Object principal = authentication.getPrincipal();
69
70 if (principal instanceof UserAccount) {
71 return (UserAccount) principal;
72 }
73 }
74 }
75
76 return null;
77 }
78
79
80 }