Skip to content

Commit

Permalink
Merge pull request #1111 from ceskaexpedice/hotfix/cdk-93-dnnt-k5
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny authored Jan 26, 2025
2 parents 44ab79d + 7455ee6 commit 1256fc5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=cz.incad.kramerius
version=7.0.40-rc4
version=7.0.40-rc5
#version=7.0.40-devmerge
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ private List<String> findLabels(User user) {
Pair<User,List<String>> retval = proxyUserHandler.user();
if (retval != null) {
licenses.addAll(retval.getValue());
Map<String, String> sessionAttributes = retval.getKey().getSessionAttributes();
sessionAttributes.keySet().forEach(key-> {
user.addSessionAttribute(oneInstance.getName()+"_"+key, sessionAttributes.get(key));
});

/** disabled attributes
*
* Map<String, String> sessionAttributes = retval.getKey().getSessionAttributes();
* sessionAttributes.keySet().forEach(key-> {
* user.addSessionAttribute(oneInstance.getName()+"_"+key, sessionAttributes.get(key));
* });
*/
}
} catch (ProxyHandlerException e) {
LOGGER.log(Level.SEVERE,e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ protected WebResource.Builder buidForwardResponse(String url, boolean headers) {
LOGGER.fine(String.format("Requesting %s", url));
WebResource r = client.resource(url);
if (headers) {
LOGGER.info("CDK_TOKEN_PARAMETERS = " + header);
String message = String.format("URL(%s), CDK_TOKEN_PARAMETERS(%s)", url, header);
LOGGER.fine(message);
return r.header("CDK_TOKEN_PARAMETERS", header);
} else {
return r.getRequestBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public Pair<User, List<String>> user() throws ProxyHandlerException {
String baseurl = forwardUrl();
String url = baseurl + (baseurl.endsWith("/") ? "" : "/") + "api/v5.0/cdk/forward/user";
ClientResponse fResponse = super.forwardedResponse(url);

if (fResponse.getStatus() != 200) {
String errorMessage = "Chyba při volání API: Status code " + fResponse.getStatus() + ", URL: " + url;
LOGGER.log(Level.SEVERE, errorMessage);
throw new ProxyHandlerException(errorMessage);
}

String entity = fResponse.getEntity(String.class);
JSONObject jObject = new JSONObject(entity);
return userFromJSON(jObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public Pair<User, List<String>> user() throws ProxyHandlerException {
String baseurl = forwardUrl();
String url = baseurl + (baseurl.endsWith("/") ? "" : "/") + "api/cdk/v7.0/forward/user";
ClientResponse fResponse = super.forwardedResponse(url);

if (fResponse.getStatus() != 200) {
String errorMessage = "Chyba při volání API: Status code " + fResponse.getStatus() + ", URL: " + url;
LOGGER.log(Level.SEVERE, errorMessage);
throw new ProxyHandlerException(errorMessage);
}

String entity = fResponse.getEntity(String.class);
JSONObject jObject = new JSONObject(entity);
return userFromJSON(jObject);
Expand Down
4 changes: 0 additions & 4 deletions search/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ jib {
}
to {
image = "ceskaexpedice/kramerius:${version}"
auth {
username = 'pavelstastny'
password = 'armoAoito1.'
}
}
container {
appRoot = '/usr/local/tomcat/webapps/search'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cz.incad.kramerius.security.User;
import cz.incad.kramerius.security.impl.UserImpl;
import cz.incad.kramerius.security.utils.UserUtils;
import cz.incad.kramerius.utils.conf.KConfiguration;
import org.keycloak.KeycloakPrincipal;
import org.keycloak.KeycloakSecurityContext;
import org.keycloak.adapters.spi.KeycloakAccount;
Expand Down Expand Up @@ -111,7 +112,24 @@ protected Keycloak3rdUser createUserWrapper(HttpServletRequest req, String userN
keycloack3rdUser.setProperty(key, object.toString());
}
});


/** K5 instance */
boolean cdkServerMode = KConfiguration.getInstance().getConfiguration().getBoolean("cdk.server.mode", false);
if (cdkServerMode) {
Set<String> allKeys = keycloack3rdUser.getPropertyKeys();
if (allKeys.contains("eduPersonScopedAffiliation") && !allKeys.contains("affiliation")) {
keycloack3rdUser.setProperty("affiliation", keycloack3rdUser.getProperty("eduPersonScopedAffiliation"));
}
if (allKeys.contains("eduPersonEntitlement") && !allKeys.contains("entitlement")) {
keycloack3rdUser.setProperty("entitlement", keycloack3rdUser.getProperty("eduPersonEntitlement"));
}
if (allKeys.contains("preffered_user_name") && !allKeys.contains("remote_user")) {
keycloack3rdUser.setProperty("remote_user", keycloack3rdUser.getProperty("preffered_user_name"));


}
}

/** standard dnnt user role */
StandardDNNTUsersSupport.makeSureDNNTUsersRole(keycloack3rdUser);

Expand Down

0 comments on commit 1256fc5

Please sign in to comment.