Skip to content

Commit 4bc1851

Browse files
committed
Merge branch 'che-multiuser' into spi
2 parents d9df07b + be4dcd3 commit 4bc1851

143 files changed

Lines changed: 4034 additions & 936 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assembly-multiuser/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/MultiUserCheWsMasterModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.eclipse.che.api.user.server.spi.UserDao;
1919
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactoryImpl;
2020
import org.eclipse.che.inject.DynaModule;
21+
import org.eclipse.che.mail.template.ST.STTemplateProcessorImpl;
22+
import org.eclipse.che.mail.template.TemplateProcessor;
2123
import org.eclipse.che.multiuser.api.permission.server.AdminPermissionInitializer;
2224
import org.eclipse.che.multiuser.api.permission.server.PermissionChecker;
2325
import org.eclipse.che.multiuser.api.permission.server.PermissionCheckerImpl;
@@ -41,6 +43,8 @@ protected void configure() {
4143
bind(InstallerConfigProvisioner.class).to(MultiuserInstallerConfigProvisioner.class);
4244
install(new OpenShiftInfraModule());
4345

46+
bind(TemplateProcessor.class).to(STTemplateProcessorImpl.class);
47+
4448
bind(DataSource.class).toProvider(org.eclipse.che.core.db.JndiDataSourceProvider.class);
4549
install(new org.eclipse.che.multiuser.api.permission.server.jpa.SystemPermissionsJpaModule());
4650
install(new org.eclipse.che.multiuser.api.permission.server.PermissionsModule());

assembly-multiuser/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/multiuser.properties

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,49 @@ che.limits.organization.workspaces.ram=-1
7474
# additional workspaces. This applies to the total number of both running
7575
# and stopped workspaces. Since each workspace is saved as a snapshot, placing a
7676
# cap on this number limits the disk consumption for workspace storage.
77-
7877
che.limits.organization.workspaces.count=-1
78+
7979
# The maximum number of running workspaces that a single organization is allowed.
8080
# If the organization has reached this threshold and they try to start an
8181
# additional workspace, they will be prompted with an error message. The
8282
# organization will need to stop a running workspace to activate another.
8383
che.limits.organization.workspaces.run.count=-1
8484

85+
# Address that will be used as from email for email notifications
86+
che.mail.from_email_address=che@noreply.com
87+
88+
##### ORGANIZATIONS' NOTIFICATIONS SETTINGS #####
89+
90+
che.organization.email.member_added_subject=You've been added to a Che Organization
91+
che.organization.email.member_added_template=st-html-templates/user_added_to_organization
92+
93+
che.organization.email.member_removed_subject=You've been removed from a Che Organization
94+
che.organization.email.member_removed_template=st-html-templates/user_removed_from_organization
95+
96+
che.organization.email.org_removed_subject=Che Organization deleted
97+
che.organization.email.org_removed_template=st-html-templates/organization_deleted
98+
99+
che.organization.email.org_renamed_subject=Che Organization renamed
100+
che.organization.email.org_renamed_template=st-html-templates/organization_renamed
101+
102+
##### KEYCLOACK CONFIGURATION #####
103+
104+
# Url to keycloak identity provider server
105+
che.keycloak.auth_server_url=http://${CHE_HOST}:5050/auth
106+
107+
# Keycloak realm is used to authenticate users
108+
che.keycloak.realm=che
109+
110+
# Keycloak client id in che.keycloak.realm that is used by dashboard, ide and cli to authenticate users
111+
che.keycloak.client_id=che-public
112+
113+
# Redhat che specific configuration
114+
115+
# URL to access OSO oauth tokens
116+
che.keycloak.oso.endpoint=NULL
117+
118+
# URL to access Github oauth tokens
119+
che.keycloak.github.endpoint=NULL
120+
121+
# The number of seconds to tolerate for clock skew when verifying exp or nbf claims.
122+
che.keycloak.allowed_clock_skew_sec=3

core/che-core-api-core/src/test/java/org/eclipse/che/api/core/PagesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void eagerlyStreamsAllElements() {
5555
}
5656

5757
@Test
58-
public void eagerlyIteratesAllElements() {
58+
public void eagerlyIteratesAllElements() throws Exception {
5959
ArrayList<String> result = Lists.newArrayList(Pages.iterate(testSource::getStrings, 2));
6060

6161
assertEquals(result, testSource.strings);

core/commons/che-core-commons-mail/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<groupId>javax.mail</groupId>
4343
<artifactId>mail</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>org.antlr</groupId>
47+
<artifactId>ST4</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>org.eclipse.che.core</groupId>
4751
<artifactId>che-core-commons-annotations</artifactId>

core/commons/che-core-commons-mail/src/main/java/org/eclipse/che/mail/EmailBean.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @author Alexander Garagatyi
2222
*/
2323
public class EmailBean {
24+
2425
private String from;
2526
private String to;
2627
private String replyTo;
@@ -29,6 +30,36 @@ public class EmailBean {
2930
private String subject;
3031
private List<Attachment> attachments;
3132

33+
public EmailBean() {}
34+
35+
public EmailBean(EmailBean email) {
36+
this(
37+
email.getFrom(),
38+
email.getTo(),
39+
email.getReplyTo(),
40+
email.getMimeType(),
41+
email.getBody(),
42+
email.getSubject(),
43+
email.getAttachments());
44+
}
45+
46+
public EmailBean(
47+
String from,
48+
String to,
49+
String replyTo,
50+
String mimeType,
51+
String body,
52+
String subject,
53+
List<Attachment> attachments) {
54+
this.from = from;
55+
this.to = to;
56+
this.replyTo = replyTo;
57+
this.mimeType = mimeType;
58+
this.body = body;
59+
this.subject = subject;
60+
this.attachments = attachments;
61+
}
62+
3263
public String getFrom() {
3364
return from;
3465
}
@@ -123,8 +154,12 @@ public EmailBean withAttachments(List<Attachment> attachments) {
123154

124155
@Override
125156
public boolean equals(Object o) {
126-
if (this == o) return true;
127-
if (!(o instanceof EmailBean)) return false;
157+
if (this == o) {
158+
return true;
159+
}
160+
if (!(o instanceof EmailBean)) {
161+
return false;
162+
}
128163
EmailBean emailBean = (EmailBean) o;
129164
return Objects.equals(getFrom(), emailBean.getFrom())
130165
&& Objects.equals(getTo(), emailBean.getTo())

core/commons/che-core-commons-mail/src/main/java/org/eclipse/che/mail/MailSessionProvider.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@
2121
import javax.mail.PasswordAuthentication;
2222
import javax.mail.Session;
2323
import org.eclipse.che.inject.ConfigurationProperties;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
2426

2527
/** Provider of {@link Session} */
2628
@Singleton
2729
public class MailSessionProvider implements Provider<Session> {
30+
private static final Logger LOG = LoggerFactory.getLogger(MailSessionProvider.class);
2831

2932
private final Session session;
33+
3034
/**
31-
* Configuration can be injected from container with help of {@lin ConfigurationProperties} class.
32-
* In this case all properties that starts with 'che.mail.' will be used to create {@link
35+
* Configuration can be injected from container with help of {@link ConfigurationProperties}
36+
* class. In this case all properties that starts with 'che.mail.' will be used to create {@link
3337
* Session}. First 4 letters 'che.' from property names will be removed.
3438
*/
3539
@Inject
3640
public MailSessionProvider(ConfigurationProperties configurationProperties) {
37-
3841
this(
3942
configurationProperties
4043
.getProperties("che.mail.*")
@@ -70,14 +73,15 @@ protected PasswordAuthentication getPasswordAuthentication() {
7073
this.session = Session.getInstance(props);
7174
}
7275
} else {
76+
LOG.warn("Mail server is not configured. Sending of emails won't work.");
7377
this.session = null;
7478
}
7579
}
7680

7781
@Override
7882
public Session get() {
7983
if (session == null) {
80-
throw new RuntimeException("SMTP is not configured");
84+
throw new RuntimeException("Mail server is not configured");
8185
}
8286
return session;
8387
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.mail.template.ST;
12+
13+
import com.google.common.io.CharStreams;
14+
import java.io.IOException;
15+
import java.io.InputStreamReader;
16+
import java.io.Reader;
17+
import java.util.Map;
18+
import javax.inject.Singleton;
19+
import org.eclipse.che.commons.lang.IoUtil;
20+
import org.eclipse.che.mail.template.Template;
21+
import org.eclipse.che.mail.template.TemplateProcessor;
22+
import org.eclipse.che.mail.template.exception.TemplateException;
23+
import org.eclipse.che.mail.template.exception.TemplateNotFoundException;
24+
import org.stringtemplate.v4.ST;
25+
26+
/**
27+
* {@link TemplateProcessor} implementation based on {@link ST}.
28+
*
29+
* @author Sergii Leshchenko
30+
*/
31+
@Singleton
32+
public class STTemplateProcessorImpl implements TemplateProcessor {
33+
34+
@Override
35+
public String process(String templateName, Map<String, Object> variables)
36+
throws TemplateException {
37+
ST st = new ST(resolve(templateName));
38+
variables.forEach(st::add);
39+
return st.render();
40+
}
41+
42+
@Override
43+
public String process(Template template) throws TemplateException {
44+
return process(template.getName(), template.getAttributes());
45+
}
46+
47+
private String resolve(String template) throws TemplateNotFoundException {
48+
try (Reader reader = new InputStreamReader(IoUtil.getResource(template))) {
49+
return CharStreams.toString(reader);
50+
} catch (IOException e) {
51+
throw new TemplateNotFoundException(e.getMessage(), e);
52+
}
53+
}
54+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.mail.template;
12+
13+
import java.util.Map;
14+
15+
/**
16+
* Holds information that is required for template processing.
17+
*
18+
* @author Sergii Leshchenko
19+
*/
20+
public class Template {
21+
22+
private final String templateName;
23+
private final Map<String, Object> attributes;
24+
25+
public Template(String templateName, Map<String, Object> attributes) {
26+
this.templateName = templateName;
27+
this.attributes = attributes;
28+
}
29+
30+
/**
31+
* Returns template name.
32+
*
33+
* @see ClassLoader#getResource(String)
34+
*/
35+
public String getName() {
36+
return templateName;
37+
}
38+
39+
/** Returns attributes which will be used while template processing. */
40+
public Map<String, Object> getAttributes() {
41+
return attributes;
42+
}
43+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.mail.template;
12+
13+
import java.util.Map;
14+
import org.eclipse.che.mail.template.exception.TemplateException;
15+
import org.eclipse.che.mail.template.exception.TemplateNotFoundException;
16+
17+
/**
18+
* Provides ability to process templates.
19+
*
20+
* <p>Note that variables definition format is implementation specific.
21+
*
22+
* @author Anton Korneta
23+
* @author Sergii Leshchenko
24+
*/
25+
public interface TemplateProcessor {
26+
27+
/**
28+
* Process specified template with given variables.
29+
*
30+
* @param templateName the template name which will be used for processing
31+
* @param variables the variables to used while processing of the given template
32+
* @return processed template as string
33+
* @throws TemplateNotFoundException when given {@code template} not found
34+
* @throws TemplateException when any another problem occurs during the template processing
35+
* @see ClassLoader#getResource(String)
36+
*/
37+
String process(String templateName, Map<String, Object> variables) throws TemplateException;
38+
39+
/**
40+
* Process the specified template.
41+
*
42+
* @param template the template to process
43+
* @return processed template as string
44+
* @throws TemplateNotFoundException when given {@code template} not found
45+
* @throws TemplateException when any another problem occurs during the template processing
46+
*/
47+
String process(Template template) throws TemplateException;
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.mail.template.exception;
12+
13+
/**
14+
* Should be thrown when any exception occurs unable while template processing.
15+
*
16+
* @author Sergii Leshchenko
17+
*/
18+
public class TemplateException extends Exception {
19+
20+
public TemplateException(String message) {
21+
super(message);
22+
}
23+
24+
public TemplateException(String message, Throwable cause) {
25+
super(message, cause);
26+
}
27+
}

0 commit comments

Comments
 (0)