dlab-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhl...@apache.org
Subject [incubator-dlab] 01/01: DLAB-000 removed hardcoded credentials
Date Thu, 01 Aug 2019 14:04:49 GMT
This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch dlab_refactored
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit fa518e26fe970bb001c1a556faad44b20b73aede
Author: bhliva <bohdan_hliva@epam.com>
AuthorDate: Thu Aug 1 16:59:52 2019 +0300

    DLAB-000 removed hardcoded credentials
---
 .../main/java/com/epam/dlab/backendapi/roles/UserRoles.java    |  6 +-----
 .../com/epam/dlab/backendapi/service/KeycloakServiceImpl.java  | 10 +++++++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
b/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
index 0767c64..2113612 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/roles/UserRoles.java
@@ -97,12 +97,8 @@ public class UserRoles {
 
 	public static boolean isAdmin(UserInfo userInfo) {
 		final List<UserRole> roles = UserRoles.getRoles();
-		if (roles == null || roles.isEmpty()) {
-			System.out.println("=============EMPTY==========");
-		}
-		final boolean b = roles == null || roles.stream().anyMatch(r -> ADMIN_ROLE_NAME.equals(r.getId())
&&
+		return roles == null || roles.stream().anyMatch(r -> ADMIN_ROLE_NAME.equals(r.getId())
&&
 				(userRoles.hasAccessByGroup(userInfo, r, userInfo.getRoles()) || userRoles.hasAccessByUserName(userInfo,
r)));
-		return b;
 	}
 
 	/**
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/KeycloakServiceImpl.java
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/KeycloakServiceImpl.java
index 30ece2d..f518bd0 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/KeycloakServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/KeycloakServiceImpl.java
@@ -3,6 +3,8 @@ package com.epam.dlab.backendapi.service;
 import com.epam.dlab.backendapi.SelfServiceApplicationConfiguration;
 import com.epam.dlab.exceptions.DlabException;
 import com.google.inject.Inject;
+import de.ahus1.keycloak.dropwizard.KeycloakConfiguration;
+import org.glassfish.jersey.internal.util.Base64;
 import org.keycloak.representations.AccessTokenResponse;
 
 import javax.ws.rs.client.Client;
@@ -15,12 +17,12 @@ public class KeycloakServiceImpl implements KeycloakService {
 
 	private static final String URI = "http://52.11.45.11:8080/auth/realms/DLAB_bhliva/protocol/openid-connect/token";
 	private final Client httpClient;
-	private final SelfServiceApplicationConfiguration conf;
+	private final KeycloakConfiguration conf;
 
 	@Inject
 	public KeycloakServiceImpl(Client httpClient, SelfServiceApplicationConfiguration conf)
{
 		this.httpClient = httpClient;
-		this.conf = conf;
+		this.conf = conf.getKeycloakConfiguration();
 	}
 
 	@Override
@@ -34,8 +36,10 @@ public class KeycloakServiceImpl implements KeycloakService {
 	}
 
 	private AccessTokenResponse requestToken(Form requestForm) {
+		final String credentials = Base64.encodeAsString(String.join(":", conf.getResource(),
+				String.valueOf(conf.getCredentials().get("secret"))));
 		final Response response = httpClient.target(URI).request()
-				.header(HttpHeaders.AUTHORIZATION, "Basic c3NzOjM3MzM4Y2M1LTc3ZjktNDdmOS05ZDk1LTVjYjcxNmI5MTExOA==")
+				.header(HttpHeaders.AUTHORIZATION, "Basic " + credentials)
 				.post(Entity.form(requestForm));
 		if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
 			throw new DlabException("can not get token");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org


Mime
View raw message