Skip to content

Commit f3d89ae

Browse files
authored
Merge pull request #59 from PizzaFactory/prp-update-to-the-upstream
[Scheduled] Update to the upstream
2 parents 5c4d91c + 9f86fe4 commit f3d89ae

File tree

13 files changed

+714
-239
lines changed

13 files changed

+714
-239
lines changed

.github/workflows/release-changelog.yml

-84
This file was deleted.

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ che.auth.access_denied_error_page=/error-oauth
194194
# Reserved user names
195195
che.auth.reserved_user_names=
196196

197-
# Configuration of GitHub OAuth client.
198-
# You can setup GitHub OAuth to automate authentication to remote repositories.
199-
# You need to first register this application with GitHub OAuth.
200-
# GitHub OAuth client ID.
201-
che.oauth.github.clientid=NULL
202-
203-
# GitHub OAuth client secret.
204-
che.oauth.github.clientsecret=NULL
197+
198+
# Configuration of GitHub OAuth2 client. Used to obtain Personal access tokens.
199+
# Location of the file with GitHub client id.
200+
che.oauth2.github.clientid_filepath=NULL
201+
202+
# Location of the file with GitHub client secret.
203+
che.oauth2.github.clientsecret_filepath=NULL
205204

206205
# GitHub OAuth authorization URI.
207206
che.oauth.github.authuri= https://github.com/login/oauth/authorize

dockerfiles/che/rhel.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111

1212
# https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi8-minimal
13-
FROM registry.access.redhat.com/ubi8-minimal:8.4-212
13+
FROM registry.access.redhat.com/ubi8-minimal:8.5-204
1414
USER root
1515
ENV CHE_HOME=/home/user/eclipse-che
1616
ENV JAVA_HOME=/usr/lib/jvm/jre

wsmaster/che-core-api-auth-github/pom.xml

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@
6060
<artifactId>che-core-commons-inject</artifactId>
6161
</dependency>
6262
<dependency>
63-
<groupId>org.eclipse.che.core</groupId>
64-
<artifactId>che-core-commons-json</artifactId>
63+
<groupId>org.slf4j</groupId>
64+
<artifactId>slf4j-api</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.testng</groupId>
68+
<artifactId>testng</artifactId>
69+
<scope>test</scope>
6570
</dependency>
6671
</dependencies>
6772
</project>

wsmaster/che-core-api-auth-github/src/main/java/org/eclipse/che/security/oauth/GitHubOAuthAuthenticator.java

+18-126
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,31 @@
1717
import jakarta.mail.internet.AddressException;
1818
import jakarta.mail.internet.InternetAddress;
1919
import java.io.IOException;
20-
import java.io.InputStream;
21-
import java.lang.reflect.Type;
22-
import java.net.HttpURLConnection;
23-
import java.net.URL;
24-
import javax.inject.Inject;
25-
import javax.inject.Named;
2620
import javax.inject.Singleton;
2721
import org.eclipse.che.api.auth.shared.dto.OAuthToken;
28-
import org.eclipse.che.commons.annotation.Nullable;
29-
import org.eclipse.che.commons.json.JsonHelper;
30-
import org.eclipse.che.commons.json.JsonParseException;
3122
import org.eclipse.che.security.oauth.shared.User;
3223

3324
/** OAuth authentication for github account. */
3425
@Singleton
3526
public class GitHubOAuthAuthenticator extends OAuthAuthenticator {
36-
@Inject
3727
public GitHubOAuthAuthenticator(
38-
@Nullable @Named("che.oauth.github.clientid") String clientId,
39-
@Nullable @Named("che.oauth.github.clientsecret") String clientSecret,
40-
@Nullable @Named("che.oauth.github.redirecturis") String[] redirectUris,
41-
@Nullable @Named("che.oauth.github.authuri") String authUri,
42-
@Nullable @Named("che.oauth.github.tokenuri") String tokenUri)
28+
String clientId, String clientSecret, String[] redirectUris, String authUri, String tokenUri)
4329
throws IOException {
44-
if (!isNullOrEmpty(clientId)
45-
&& !isNullOrEmpty(clientSecret)
46-
&& !isNullOrEmpty(authUri)
47-
&& !isNullOrEmpty(tokenUri)
48-
&& redirectUris != null
49-
&& redirectUris.length != 0) {
50-
51-
configure(
52-
clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory());
53-
}
30+
configure(
31+
clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory());
5432
}
5533

5634
@Override
5735
public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException {
5836
GitHubUser user =
59-
getJson(
60-
"https://api.github.com/user?access_token=" + accessToken.getToken(), GitHubUser.class);
61-
62-
GithubEmail[] result =
63-
getJson2(
64-
"https://api.github.com/user/emails?access_token=" + accessToken.getToken(),
65-
GithubEmail[].class,
66-
null);
37+
getJson("https://api.github.com/user", accessToken.getToken(), GitHubUser.class);
38+
final String email = user.getEmail();
6739

68-
GithubEmail verifiedEmail = null;
69-
for (GithubEmail email : result) {
70-
if (email.isPrimary() && email.isVerified()) {
71-
verifiedEmail = email;
72-
break;
73-
}
74-
}
75-
if (verifiedEmail == null
76-
|| verifiedEmail.getEmail() == null
77-
|| verifiedEmail.getEmail().isEmpty()) {
40+
if (isNullOrEmpty(email)) {
7841
throw new OAuthAuthenticationException(
7942
"Sorry, we failed to find any verified emails associated with your GitHub account."
8043
+ " Please, verify at least one email in your GitHub account and try to connect with GitHub again.");
8144
}
82-
user.setEmail(verifiedEmail.getEmail());
83-
final String email = user.getEmail();
8445
try {
8546
new InternetAddress(email).validate();
8647
} catch (AddressException e) {
@@ -89,32 +50,6 @@ public User getUser(OAuthToken accessToken) throws OAuthAuthenticationException
8950
return user;
9051
}
9152

92-
protected <O> O getJson2(String getUserUrl, Class<O> userClass, Type type)
93-
throws OAuthAuthenticationException {
94-
HttpURLConnection urlConnection = null;
95-
InputStream urlInputStream = null;
96-
97-
try {
98-
urlConnection = (HttpURLConnection) new URL(getUserUrl).openConnection();
99-
urlConnection.setRequestProperty("Accept", "application/vnd.github.v3.html+json");
100-
urlInputStream = urlConnection.getInputStream();
101-
return JsonHelper.fromJson(urlInputStream, userClass, type);
102-
} catch (JsonParseException | IOException e) {
103-
throw new OAuthAuthenticationException(e.getMessage(), e);
104-
} finally {
105-
if (urlInputStream != null) {
106-
try {
107-
urlInputStream.close();
108-
} catch (IOException ignored) {
109-
}
110-
}
111-
112-
if (urlConnection != null) {
113-
urlConnection.disconnect();
114-
}
115-
}
116-
}
117-
11853
@Override
11954
public final String getOAuthProvider() {
12055
return "github";
@@ -123,62 +58,19 @@ public final String getOAuthProvider() {
12358
@Override
12459
public OAuthToken getToken(String userId) throws IOException {
12560
final OAuthToken token = super.getToken(userId);
126-
if (!(token == null || token.getToken() == null || token.getToken().isEmpty())) {
127-
// Need to check if token which stored is valid for requests, then if valid - we returns it to
128-
// caller
129-
String tokenVerifyUrl = "https://api.github.com/?access_token=" + token.getToken();
130-
HttpURLConnection http = null;
131-
try {
132-
http = (HttpURLConnection) new URL(tokenVerifyUrl).openConnection();
133-
http.setInstanceFollowRedirects(false);
134-
http.setRequestMethod("GET");
135-
http.setRequestProperty("Accept", "application/json");
136-
137-
if (http.getResponseCode() == 401) {
138-
return null;
139-
}
140-
} finally {
141-
if (http != null) {
142-
http.disconnect();
143-
}
61+
// Need to check if token which is stored is valid for requests, then if valid - we returns it
62+
// to
63+
// caller
64+
try {
65+
if (token == null
66+
|| token.getToken() == null
67+
|| token.getToken().isEmpty()
68+
|| getJson("https://api.github.com/user", token.getToken(), GitHubUser.class) == null) {
69+
return null;
14470
}
145-
146-
return token;
147-
}
148-
return null;
149-
}
150-
151-
/**
152-
* information for each email address indicating if the address has been verified and if it’s the
153-
* user’s primary email address for GitHub.
154-
*/
155-
public static class GithubEmail {
156-
private boolean primary;
157-
private boolean verified;
158-
private String email;
159-
160-
public boolean isPrimary() {
161-
return primary;
162-
}
163-
164-
public void setPrimary(boolean primary) {
165-
this.primary = primary;
166-
}
167-
168-
public boolean isVerified() {
169-
return verified;
170-
}
171-
172-
public void setVerified(boolean verified) {
173-
this.verified = verified;
174-
}
175-
176-
public String getEmail() {
177-
return email;
178-
}
179-
180-
public void setEmail(String email) {
181-
this.email = email;
71+
} catch (OAuthAuthenticationException e) {
72+
return null;
18273
}
74+
return token;
18375
}
18476
}

0 commit comments

Comments
 (0)