Revize fab2885e
Přidáno uživatelem Michal Linha před asi 4 roky(ů)
src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java | ||
---|---|---|
5 | 5 |
import org.springframework.context.event.ContextRefreshedEvent; |
6 | 6 |
import org.springframework.context.event.EventListener; |
7 | 7 |
import org.springframework.core.annotation.Order; |
8 |
import org.springframework.security.authentication.AnonymousAuthenticationToken; |
|
9 |
import org.springframework.security.core.Authentication; |
|
10 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
8 | 11 |
import org.springframework.stereotype.Service; |
9 | 12 |
import vldc.aswi.dao.*; |
10 | 13 |
import vldc.aswi.dao.parameter.ParameterInConfigurationRepository; |
11 |
import vldc.aswi.dao.parameter.ParameterTypeRepository; |
|
12 |
import vldc.aswi.domain.Assembly; |
|
13 |
import vldc.aswi.domain.Configuration; |
|
14 |
import vldc.aswi.domain.Function; |
|
14 |
import vldc.aswi.domain.*; |
|
15 | 15 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
16 | 16 |
import vldc.aswi.service.parameter.ParameterInConfigurationManager; |
17 | 17 |
import vldc.aswi.service.parameter.ParameterTypeManager; |
18 |
import vldc.aswi.utils.AuthControl; |
|
18 | 19 |
|
19 | 20 |
import javax.transaction.Transactional; |
20 | 21 |
import java.util.ArrayList; |
21 |
import java.util.LinkedList; |
|
22 | 22 |
import java.util.List; |
23 | 23 |
|
24 | 24 |
@Service |
... | ... | |
83 | 83 |
*/ |
84 | 84 |
@Override |
85 | 85 |
public List<Configuration> getConfigurations() { |
86 |
List<Configuration> retVal = new LinkedList<>(); |
|
87 |
this.configurationRepository.findAll().forEach(retVal::add); |
|
88 |
return retVal; |
|
86 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
87 |
String username; |
|
88 |
if (!(authentication instanceof AnonymousAuthenticationToken)) { |
|
89 |
username = authentication.getName(); |
|
90 |
} |
|
91 |
else { |
|
92 |
// TODO: 04.05.2020 error message, user not authenticated |
|
93 |
return null; |
|
94 |
} |
|
95 |
User user = userRepository.findByUsername(username); |
|
96 |
|
|
97 |
return configurationRepository.getByUserEquals(user); |
|
89 | 98 |
} |
90 | 99 |
|
91 | 100 |
/** |
... | ... | |
106 | 115 |
*/ |
107 | 116 |
@Override |
108 | 117 |
public Configuration saveConfiguration(Configuration newConfiguration, String id) { |
109 |
if(id.equals("")) { |
|
118 |
if (id.equals("")) {
|
|
110 | 119 |
return addConfiguration(newConfiguration); |
111 | 120 |
} |
112 | 121 |
else { |
... | ... | |
158 | 167 |
* @return saved configuration |
159 | 168 |
*/ |
160 | 169 |
private Configuration addConfiguration(Configuration newConfiguration) { |
170 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
171 |
String username = AuthControl.getUserName(); |
|
172 |
if (username == null) { |
|
173 |
// TODO: 04.05.2020 error message, user not authenticated |
|
174 |
} |
|
161 | 175 |
Configuration configuration = new Configuration(); |
162 | 176 |
Assembly assembly = assemblyRepository.getById(newConfiguration.getAssembly().getId()); |
163 | 177 |
configuration.setAssembly(assembly); |
164 | 178 |
configuration.setName(newConfiguration.getName()); |
165 | 179 |
configuration.setTableName(newConfiguration.getTableName()); |
166 |
configuration.setUser(userRepository.getById((long) 1));
|
|
180 |
configuration.setUser(userRepository.findByUsername(username));
|
|
167 | 181 |
Configuration savedConfiguration = configurationRepository.save(configuration); |
168 | 182 |
|
169 | 183 |
savedConfiguration.setParametersInConfiguration(new ArrayList<>()); |
Také k dispozici: Unified diff
re #7978 added functionality of only showing assemblies with correct role (same as user), added functionality of showing only logged in users's configurations in "Rychle k"