Revision 1d4b43d8
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java | ||
---|---|---|
15 | 15 |
import javax.servlet.annotation.WebServlet; |
16 | 16 |
|
17 | 17 |
import org.apache.log4j.Logger; |
18 |
import org.springframework.beans.BeansException; |
|
18 | 19 |
import org.springframework.beans.factory.annotation.Autowired; |
20 |
import org.springframework.context.ApplicationContext; |
|
21 |
import org.springframework.context.ApplicationContextAware; |
|
19 | 22 |
import org.springframework.context.annotation.Bean; |
20 | 23 |
import org.springframework.context.annotation.ComponentScan; |
21 | 24 |
import org.springframework.context.annotation.ComponentScan.Filter; |
22 | 25 |
import org.springframework.context.annotation.Configuration; |
23 | 26 |
import org.springframework.context.annotation.FilterType; |
24 | 27 |
import org.springframework.context.annotation.Lazy; |
28 |
import org.springframework.security.authentication.AuthenticationProvider; |
|
25 | 29 |
|
26 | 30 |
import com.vaadin.server.DeploymentConfiguration; |
27 | 31 |
import com.vaadin.server.ServiceException; |
... | ... | |
32 | 36 |
import com.vaadin.spring.server.SpringVaadinServlet; |
33 | 37 |
import com.vaadin.ui.UI; |
34 | 38 |
|
39 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
35 | 40 |
import eu.etaxonomy.cdm.common.ConfigFileUtil; |
41 |
import eu.etaxonomy.cdm.dataInserter.RegistrationRequiredDataInserter; |
|
36 | 42 |
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer; |
37 | 43 |
import eu.etaxonomy.cdm.vaadin.security.annotation.EnableAnnotationBasedAccessControl; |
38 | 44 |
import eu.etaxonomy.cdm.vaadin.server.CdmSpringVaadinServletService; |
... | ... | |
53 | 59 |
@ComponentScan(basePackages={ |
54 | 60 |
"eu.etaxonomy.vaadin.ui", |
55 | 61 |
"eu.etaxonomy.cdm.vaadin", |
56 |
"eu.etaxonomy.cdm.dataInserter", |
|
57 | 62 |
"eu.etaxonomy.cdm.service", |
58 |
"eu.etaxonomy.cdm.vaadin.component", // for the FieldFactories |
|
59 | 63 |
"org.springframework.context.event" |
60 | 64 |
}, |
61 | 65 |
// exclude UI classes, these are provided via the @Bean annotated methods below |
... | ... | |
67 | 71 |
@EnableVaadin // this imports VaadinConfiguration |
68 | 72 |
@EnableVaadinSpringNavigation // activate the NavigationManagerBean |
69 | 73 |
@EnableAnnotationBasedAccessControl // enable annotation based per view access control |
70 |
public class CdmVaadinConfiguration { |
|
74 |
public class CdmVaadinConfiguration implements ApplicationContextAware {
|
|
71 | 75 |
|
72 | 76 |
/** |
73 | 77 |
* |
... | ... | |
97 | 101 |
throws ServiceException { |
98 | 102 |
|
99 | 103 |
// - The SpringVaadinServletService is needed when using a custom service URL |
100 |
// - The CdmSpringVaadinServletService allows to attach listeners to the requestEnd and
|
|
101 |
// requestStart method this is important for proper unbinding of Conversations from
|
|
104 |
// - The CdmSpringVaadinServletService allows to attach listeners to the requestEnd and |
|
105 |
// requestStart method this is important for proper unbinding of Conversations from |
|
102 | 106 |
// the request threads. |
103 | 107 |
// see ViewScopeConversationHolder |
104 | 108 |
CdmSpringVaadinServletService service = new CdmSpringVaadinServletService( |
... | ... | |
161 | 165 |
} |
162 | 166 |
|
163 | 167 |
@Bean |
168 |
public RegistrationRequiredDataInserter registrationRequiredDataInserter() throws BeansException, InactiveUIException{ |
|
169 |
RegistrationRequiredDataInserter inserter = null; |
|
170 |
if(isUIEnabled(RegistrationUI.class)){ |
|
171 |
inserter = new RegistrationRequiredDataInserter(); |
|
172 |
inserter.setRunAsAuthenticationProvider((AuthenticationProvider) applicationContext.getBean("runAsAuthenticationProvider")); |
|
173 |
inserter.setCdmRepository((CdmRepository) applicationContext.getBean("cdmRepository")); |
|
174 |
} |
|
175 |
return inserter; |
|
176 |
} |
|
177 |
|
|
178 |
@Bean |
|
164 | 179 |
@UIScope |
165 | 180 |
public DistributionStatusUI distributionStatusUI() throws InactiveUIException { |
166 | 181 |
if(isUIEnabled(DistributionStatusUI.class)){ |
... | ... | |
178 | 193 |
return null; |
179 | 194 |
} |
180 | 195 |
|
181 |
|
|
182 |
|
|
183 | 196 |
static final String PROPERTIES_NAME = "vaadin-apps"; |
184 | 197 |
|
185 | 198 |
private Properties appProps = null; |
186 | 199 |
|
200 |
private ApplicationContext applicationContext; |
|
201 |
|
|
187 | 202 |
//@formatter:off |
188 | 203 |
private static final String APP_FILE_CONTENT= |
189 | 204 |
"########################################################\n"+ |
... | ... | |
209 | 224 |
* @throws InactiveUIException |
210 | 225 |
*/ |
211 | 226 |
private boolean isUIEnabled(Class<? extends UI>uiClass) throws InactiveUIException { |
227 |
|
|
212 | 228 |
String path = uiClass.getAnnotation(SpringUI.class).path().trim(); |
213 | 229 |
|
214 | 230 |
try { |
... | ... | |
224 | 240 |
return true; |
225 | 241 |
} |
226 | 242 |
} |
227 |
throw new InactiveUIException(path); |
|
243 |
throw new InactiveUIException(path); // FIXME should return false instead
|
|
228 | 244 |
} catch (IOException e) { |
229 | 245 |
logger.error("Error reading the vaadin ui properties file. File corrupted?. Stopping instance ..."); |
230 | 246 |
throw new RuntimeException(e); |
231 | 247 |
} |
232 | 248 |
} |
233 | 249 |
|
250 |
/** |
|
251 |
* {@inheritDoc} |
|
252 |
*/ |
|
253 |
@Override |
|
254 |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
|
255 |
this.applicationContext = applicationContext; |
|
256 |
|
|
257 |
} |
|
258 |
|
|
234 | 259 |
|
235 | 260 |
} |
src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.io.IOException; |
12 | 12 |
import java.util.ArrayList; |
13 |
import java.util.Arrays; |
|
13 | 14 |
import java.util.HashMap; |
14 | 15 |
import java.util.HashSet; |
15 | 16 |
import java.util.List; |
... | ... | |
20 | 21 |
import org.apache.log4j.Logger; |
21 | 22 |
import org.joda.time.DateTime; |
22 | 23 |
import org.joda.time.format.DateTimeFormatter; |
23 |
import org.springframework.beans.factory.annotation.Autowired; |
|
24 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
25 | 24 |
import org.springframework.context.ApplicationListener; |
26 | 25 |
import org.springframework.context.event.ContextRefreshedEvent; |
26 |
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; |
|
27 |
import org.springframework.security.core.GrantedAuthority; |
|
27 | 28 |
import org.springframework.transaction.TransactionStatus; |
28 |
import org.springframework.transaction.annotation.Transactional; |
|
29 | 29 |
|
30 | 30 |
import com.fasterxml.jackson.core.JsonParseException; |
31 | 31 |
import com.fasterxml.jackson.databind.JsonMappingException; |
32 | 32 |
import com.fasterxml.jackson.databind.ObjectMapper; |
33 |
import com.vaadin.spring.annotation.SpringComponent; |
|
34 | 33 |
|
35 | 34 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
35 |
import eu.etaxonomy.cdm.api.application.RunAsAuthenticator; |
|
36 | 36 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
37 | 37 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
38 | 38 |
import eu.etaxonomy.cdm.model.agent.Institution; |
39 | 39 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
40 |
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl; |
|
41 |
import eu.etaxonomy.cdm.model.common.Group; |
|
40 | 42 |
import eu.etaxonomy.cdm.model.name.Registration; |
41 | 43 |
import eu.etaxonomy.cdm.model.name.RegistrationStatus; |
42 | 44 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
... | ... | |
51 | 53 |
* @since May 9, 2017 |
52 | 54 |
* |
53 | 55 |
*/ |
54 |
@SpringComponent |
|
55 |
@Transactional(readOnly=true) |
|
56 |
public class RegistrationRequiredDataInserter implements ApplicationListener<ContextRefreshedEvent>{ |
|
56 |
public class RegistrationRequiredDataInserter extends RunAsAuthenticator implements ApplicationListener<ContextRefreshedEvent>{ |
|
57 | 57 |
|
58 | 58 |
protected static final String PARAM_NAME_CREATE = "registrationCreate"; |
59 | 59 |
|
60 | 60 |
protected static final String PARAM_NAME_WIPEOUT = "registrationWipeout"; |
61 | 61 |
|
62 |
// protected static final UUID GROUP_SUBMITTER_UUID = UUID.fromString("c468c6a7-b96c-4206-849d-5a825f806d3e"); |
|
63 |
|
|
64 |
protected static final UUID GROUP_CURATOR_UUID = UUID.fromString("135210d3-3db7-4a81-ab36-240444637d45"); |
|
65 |
|
|
62 | 66 |
private static final Logger logger = Logger.getLogger(RegistrationRequiredDataInserter.class); |
63 | 67 |
|
64 | 68 |
private ExtensionType extensionTypeIAPTRegData; |
... | ... | |
67 | 71 |
|
68 | 72 |
public static boolean commandsExecuted = false; |
69 | 73 |
|
70 |
@Autowired |
|
71 |
@Qualifier("cdmRepository") |
|
72 | 74 |
private CdmRepository repo; |
73 | 75 |
|
76 |
private boolean hasRun = false; |
|
77 |
|
|
78 |
public void setCdmRepository(CdmRepository repo){ |
|
79 |
this.repo = repo; |
|
80 |
} |
|
81 |
|
|
82 |
|
|
74 | 83 |
// ==================== Registration creation ======================= // |
75 | 84 |
|
76 | 85 |
/** |
... | ... | |
78 | 87 |
*/ |
79 | 88 |
@Override |
80 | 89 |
public void onApplicationEvent(ContextRefreshedEvent event) { |
90 |
|
|
91 |
if(hasRun){ |
|
92 |
return; |
|
93 |
} |
|
94 |
|
|
95 |
runAsAuthentication(Role.ROLE_ADMIN); |
|
96 |
|
|
81 | 97 |
insertRequiredData(); |
82 | 98 |
executeSuppliedCommands(); |
99 |
|
|
100 |
restoreAuthentication(); |
|
101 |
|
|
102 |
hasRun = true; |
|
83 | 103 |
} |
84 | 104 |
|
85 | 105 |
/** |
86 | 106 |
* |
87 | 107 |
*/ |
88 | 108 |
private void insertRequiredData() { |
109 |
|
|
89 | 110 |
Role roleCuration = RolesAndPermissions.ROLE_CURATION; |
90 | 111 |
if(repo.getGrantedAuthorityService().find(roleCuration.getUuid()) == null){ |
91 | 112 |
repo.getGrantedAuthorityService().saveOrUpdate(roleCuration.asNewGrantedAuthority()); |
92 | 113 |
} |
114 |
|
|
115 |
Group groupCurator = repo.getGroupService().load(GROUP_CURATOR_UUID, Arrays.asList("grantedAuthorities")); |
|
116 |
if(groupCurator == null){ |
|
117 |
groupCurator = Group.NewInstance(); |
|
118 |
groupCurator.setUuid(GROUP_CURATOR_UUID); |
|
119 |
groupCurator.setName("Curator"); |
|
120 |
} |
|
121 |
assureGroupHas(groupCurator, "REGISTRATION[CREATE,READ,UPDATE,DELETE]"); |
|
122 |
repo.getGroupService().saveOrUpdate(groupCurator); |
|
123 |
|
|
124 |
Group groupEditor = repo.getGroupService().load(Group.groupEditorUuid, Arrays.asList("grantedAuthorities")); |
|
125 |
assureGroupHas(groupEditor, "REGISTRATION[CREATE,READ]"); |
|
126 |
assureGroupHas(groupEditor, "PERSON[CREATE,READ]"); |
|
127 |
repo.getGroupService().saveOrUpdate(groupEditor); |
|
128 |
|
|
93 | 129 |
if(repo.getTermService().find(DerivationEventTypes.PUBLISHED_IMAGE().getUuid()) == null){ |
94 | 130 |
repo.getTermService().save(DerivationEventTypes.PUBLISHED_IMAGE()); |
95 | 131 |
} |
... | ... | |
103 | 139 |
|
104 | 140 |
} |
105 | 141 |
|
142 |
private void assureGroupHas(Group group, String authorityString){ |
|
143 |
boolean authorityExists = false; |
|
144 |
|
|
145 |
for(GrantedAuthority ga : group.getGrantedAuthorities()){ |
|
146 |
if((authorityExists = ga.getAuthority().equals(authorityString)) == true){ |
|
147 |
break; |
|
148 |
} |
|
149 |
} |
|
150 |
if(!authorityExists){ |
|
151 |
group.addGrantedAuthority(findGrantedAuthority(authorityString)); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
private GrantedAuthorityImpl findGrantedAuthority(String authorityString){ |
|
156 |
GrantedAuthorityImpl ga = null; |
|
157 |
try{ |
|
158 |
ga = repo.getGrantedAuthorityService().findAuthorityString(authorityString); |
|
159 |
} catch (AuthenticationCredentialsNotFoundException e){ |
|
160 |
e.printStackTrace(); |
|
161 |
} |
|
162 |
if(ga == null){ |
|
163 |
ga = GrantedAuthorityImpl.NewInstance(authorityString); |
|
164 |
repo.getGrantedAuthorityService().save(ga); |
|
165 |
} |
|
166 |
return ga; |
|
167 |
} |
|
168 |
|
|
106 | 169 |
/** |
107 | 170 |
* |
108 | 171 |
*/ |
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 12 |
import org.springframework.context.ApplicationEventPublisher; |
13 |
import org.springframework.context.annotation.Lazy; |
|
14 | 13 |
|
15 | 14 |
import com.vaadin.annotations.Theme; |
16 | 15 |
import com.vaadin.annotations.Title; |
... | ... | |
30 | 29 |
import com.vaadin.ui.UI; |
31 | 30 |
import com.vaadin.ui.themes.ValoTheme; |
32 | 31 |
|
33 |
import eu.etaxonomy.cdm.dataInserter.RegistrationRequiredDataInserter; |
|
34 | 32 |
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView; |
35 | 33 |
import eu.etaxonomy.cdm.vaadin.view.registration.DashBoardView; |
36 | 34 |
import eu.etaxonomy.cdm.vaadin.view.registration.ListViewBean; |
... | ... | |
58 | 56 |
@Autowired |
59 | 57 |
private ViewDisplay viewDisplay; |
60 | 58 |
|
61 |
/** |
|
62 |
* The RegistrationDefaultDataInserter is not used in the ui directly |
|
63 |
* but will as a ApplicationListener for ContextRefreshedEvents insert |
|
64 |
* data required for the registration application into the database. |
|
65 |
*/ |
|
66 |
@SuppressWarnings("unused") |
|
67 |
@Autowired |
|
68 |
@Lazy |
|
69 |
private RegistrationRequiredDataInserter dataInserter; |
|
70 |
|
|
71 | 59 |
//---- pull into abstract super class ? --------- |
72 | 60 |
@Autowired |
73 | 61 |
SpringViewProvider viewProvider; |
Also available in: Unified diff
fix #6852 data insterter to create Group 'Curation' and to extend 'Editor' for phycobank