Commit b044cb6f authored by Dimitrios Chalepakis's avatar Dimitrios Chalepakis
Browse files

Merge branch 'DEVELOP_BE' of ssh://git.eclipse.org:29418/elogbook/authandauth into DEVELOP_BE

parents a357f9aa 98678d83
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@

    <groupId>openk.pta.de</groupId>
    <artifactId>portal</artifactId>
    <version>1.0.1</version>
    <version>1.0.2</version>
    <packaging>war</packaging>

    <properties>
+39 −0
Original line number Diff line number Diff line
@@ -348,5 +348,44 @@ This service returns all users belonging to the specified role.

*Remarks*:

=== Get health state
This service returns the health state of this module.

*URL:* /healthcheck/pretty=true

*Method:* GET



*Request-Headers*:

* Authorization – none


*Produces*: application/json

*Response*:

If the module is healthy then...
[source,json]
----
{"Keycloak present":{"healthy":true}}
----

If the module is *not* healthy...
[source,json]
----
{
    "Keycloak present":
    {
        "healthy":false,
        "message":"<Error message>"
    }
}
----


*Remarks*:


+0 −5
Original line number Diff line number Diff line
@@ -39,13 +39,8 @@ public class KeyCloakUser {
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }

    public boolean getEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }

    public boolean getTotp() { return totp; }
    public void setTotp(boolean totp) { this.totp = totp; }

    public boolean getEmailVerified() { return emailVerified; }
    public void setEmailVerified(boolean emailVerified) { this.emailVerified = emailVerified; }

    public String getFirstName() { return firstName; }
+11 −3
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
import java.util.List;
import org.apache.log4j.Logger;
import org.eclipse.openk.portal.common.BackendConfig;
@@ -46,10 +45,19 @@ public class JwtHelper {
  public static JwtToken login(String user, String password) throws PortalInternalServerError {
    String token = sendPost(BackendConfig.getInstance().getAuthServerUrl() + "auth/realms/" +
                    BackendConfig.getInstance().getKeycloakRealm() + "/protocol/openid-connect/token",
        "username=" + user + "&password=" + password + "&client_id=" + BackendConfig.getInstance().getKeycloakClient() + "&grant_type=password");
            "username=" + user + "&password=" + password + "&client_id="
                    + BackendConfig.getInstance().getKeycloakClient() + "&grant_type=password");
    return getJwtTokenFromJson(token);
  }

  public static boolean serviceAvailable() throws PortalInternalServerError {
    String jsonRet = sendGet(BackendConfig.getInstance().getAuthServerUrl() + "auth/realms/" +
                    BackendConfig.getInstance().getKeycloakRealm(), "", null);

    return jsonRet != null ? jsonRet.contains("realm") && jsonRet.contains(BackendConfig.getInstance().getKeycloakRealm())
                           : false;
  }

  public static List<KeyCloakUser> getUsers(JwtToken jwtToken, int maxUsers) throws PortalInternalServerError {
    String users = sendGet(BackendConfig.getInstance().getAuthServerUrl() + "auth/admin/realms/" + BackendConfig.getInstance().getKeycloakRealm() + "/users?max="+maxUsers,
        MediaType.APPLICATION_JSON, jwtToken.getAccessToken());
+0 −2
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@ import org.apache.log4j.Logger;
import org.eclipse.openk.portal.auth2.model.JwtToken;
import org.eclipse.openk.portal.auth2.model.KeyCloakUser;
import org.eclipse.openk.portal.auth2.util.JwtHelper;
import org.eclipse.openk.portal.common.BackendConfig;
import org.eclipse.openk.portal.common.JsonGeneratorBase;
import org.eclipse.openk.portal.exceptions.PortalException;
import org.eclipse.openk.portal.exceptions.PortalInternalServerError;
import org.eclipse.openk.portal.exceptions.PortalUnauthorized;
import org.eclipse.openk.portal.viewmodel.LoginCredentials;
import org.eclipse.openk.portal.viewmodel.UserCache;
Loading