Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.0' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.0
  • Loading branch information
metaventis-build committed May 7, 2024
2 parents 45c126c + d1df7ec commit 930d645
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 198 deletions.
Original file line number Diff line number Diff line change
@@ -1,108 +1,57 @@
package org.edu_sharing.metadataset.v2;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class MetadataKey extends MetadataTranslatable {

public static class MetadataKeyRelated extends MetadataKey {
public enum Relation {
exactMatch,
narrowMatch,
relatedMatch,
closeMatch,
broadMatch,
};
private Relation relation;

public MetadataKeyRelated(Relation relation) {
this.relation = relation;
}

public Relation getRelation() {
return relation;
}
}
private String key,caption,description,parent,locale;
/**
* List of other keys this child is a precedor of
*/
private List<String> preceds;

private final List<MetadataKeyRelated> related = new ArrayList<>();

private List<String> alternativeKeys;

private String url;

public void setUrl(String url) {
this.url = url;
}

public String getUrl() {
return url;
}

public void setAlternativeKeys(List<String> alternativeKeys) {
this.alternativeKeys = alternativeKeys;
}

public List<String> getAlternativeKeys() {
return alternativeKeys;
}

public String getParent() {
return parent;
}

public void setParent(String parent) {
if ( parent==null || parent.trim().isEmpty() )
this.parent=null;
else
this.parent = parent;
}

public void addRelated(MetadataKeyRelated related) {
this.related.add(related);
}

public List<MetadataKeyRelated> getRelated() {
return related;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getCaption() {
return caption;
}

public void setCaption(String caption) {
this.caption = caption;
}

public List<String> getPreceds() {
return preceds;
}

public void setPreceds(List<String> preceds) {
this.preceds = preceds;
}

public void setLocale(String locale) { this.locale = locale;}

public String getLocale() { return locale;}
@Getter
public static class MetadataKeyRelated extends MetadataKey {
public enum Relation {
exactMatch,
narrowMatch,
relatedMatch,
closeMatch,
broadMatch,
}

private final Relation relation;

public MetadataKeyRelated(Relation relation) {
this.relation = relation;
}

}
private String key;
private String caption;
private String icon;
private String description;
private String parent;
private String locale;
/**
* List of other keys this child is a precedor of
*/
private List<String> preceds;
private final List<MetadataKeyRelated> related = new ArrayList<>();
private List<String> alternativeKeys;
private String url;

public void setParent(String parent) {
if (StringUtils.isBlank(parent)) {
this.parent = null;
} else {
this.parent = parent;
}
}

public void addRelated(MetadataKeyRelated related) {
this.related.add(related);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ private List<MetadataKey> getValues(NodeList keysNode, String valuespaceI18n, St
key.setI18nPrefix(valuespaceI18nPrefix);
if (attributes != null && attributes.getNamedItem("parent") != null)
key.setParent(attributes.getNamedItem("parent").getTextContent());
if (attributes != null && attributes.getNamedItem("icon") != null)
key.setIcon(attributes.getNamedItem("icon").getTextContent());
if (attributes != null && attributes.getNamedItem("url") != null)
key.setUrl(attributes.getNamedItem("url").getTextContent());
String fallback = null;
if (!cap.isEmpty()) fallback = cap;
key.setCaption(getTranslation(key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ private MetadataKey convertEntry(JSONObject entry, String labelId, String locale
String de = entry.getJSONObject(labelId).getString("de");
key.setCaption(de);
key.setLocale("de");
if("en_US".equals(locale)) {
if(locale != null && !"de_DE".equals(locale)) {
try {
key.setCaption(entry.getJSONObject(labelId).getString("en"));
key.setLocale("en");
String[] splitted=locale.split("_");
key.setCaption(entry.getJSONObject(labelId).getString(splitted[0]));
key.setLocale(splitted[0]);
}catch(JSONException ignored) { }
}
if(entry.has("notation")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,31 @@ private String renderWidgetValue(MetadataWidget widget,String value, int index){
}
}
Map<String, MetadataKey> valuesMap = widget.getValuesAsMap();
if(valuesMap.containsKey(value))
value=valuesMap.get(value).getCaption();
MetadataKey entry = null;
if(valuesMap.containsKey(value)) {
entry = valuesMap.get(value);
value = valuesMap.get(value).getCaption();
}

if(widget.getFormat()!=null && !widget.getFormat().isEmpty()){
if(widget.getFormat().contains("${value}")) {
value = widget.getFormat().replace("${value}", value);
}
}
return value;
if(entry != null) {
value = "<span class=\"value-caption\">" + value + "</span>";
if(entry.getDescription() != null) {
value += " <span class=\"value-description\">" + entry.getDescription() + "</span>";
}
if(entry.getIcon() != null) {
value = "<img src=\"" + (entry.getIcon().startsWith("http://") || entry.getIcon().startsWith("https://") ? entry.getIcon() : "assets/images/" + entry.getIcon()) + "\" alt=\"\"><div class=\"value-group\">" + value + "</div>";
}
if(entry.getUrl() != null) {
value = "<a href=\"" + entry.getUrl() + "\" target=\"_BLANK\">" + value + "</a>";
}
}

return value;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ private String getLocaleFromLanguage(String language){
Map<String,String> locales = new HashMap<>();
locales.put("de","de_DE");
locales.put("en","en_US");
locales.put("fr","fr_FR");
locales.put("it","it_IT");
return locales.get(language);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,9 @@ private DataInputStream postProcessImage(String nodeId, DataInputStream in, Http
return new DataInputStream(new ByteArrayInputStream(img));
}
BufferedImage img;
boolean svg = false;
if(Objects.equals("image/svg+xml", mimetype)) {
svg = true;
img = ImageIO.read(new ByteArrayInputStream(ImageTool.convertSvgToPng(in)));
} else {
img = ImageIO.read(in);
Expand Down Expand Up @@ -569,7 +571,7 @@ private DataInputStream postProcessImage(String nodeId, DataInputStream in, Http
scale=false;
}
}
if(!scale)
if(!scale && !svg)
return null;
BufferedImage cropped=new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB); // getType() sometimes return 0
float aspectCrop=(float)width/(float)height;
Expand Down Expand Up @@ -685,6 +687,9 @@ private void deliverImage(String mimetype, DataInputStream in, HttpServletRespon
if(mimetype.startsWith("image/svg")){
mimetype = "image/svg+xml";
}
if(mimetype.equals("image/svg+xml")) {
throw new RuntimeException("svg is not supported and could not be converted");
}
resp.setContentType(mimetype);

resp.setContentLength((int) in.available());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@
import org.edu_sharing.service.authentication.SSOAuthorityMapper;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal;
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;

public class ShibbolethServlet extends HttpServlet {

Expand Down Expand Up @@ -300,6 +303,14 @@ private String getShibValue(String attName, HttpServletRequest req){
}
return (att != null) ? att.toString() : null;
}
if(authentication instanceof Saml2Authentication){
Saml2AuthenticatedPrincipal samlAuthentication = (Saml2AuthenticatedPrincipal) authentication.getPrincipal();
if(samlAuthentication.getAttribute(attName) != null) {
return samlAuthentication.getAttribute(attName).stream().findFirst().map(Object::toString).orElse(null);
}else{
logger.info("att:" +attName +" is null");
}
}
}

String attValue = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.edu_sharing.service.authority.AuthorityServiceFactory;
import org.edu_sharing.service.config.ConfigServiceFactory;
import org.edu_sharing.service.toolpermission.ToolPermissionServiceFactory;
import org.edu_sharing.spring.security.basic.CSRFConfig;
import org.springframework.context.ApplicationContext;

public class ApiAuthenticationFilter implements jakarta.servlet.Filter {
Expand Down Expand Up @@ -77,6 +78,7 @@ public void doFilter(ServletRequest req, ServletResponse resp,
String authMethod = ("alfrescoNtlm1".equals(succsessfullAuthMethod) || "alfinst".equals(succsessfullAuthMethod)) ? CCConstants.AUTH_TYPE_DEFAULT : CCConstants.AUTH_TYPE + succsessfullAuthMethod;
String username = validatedAuth.get(CCConstants.AUTH_USERNAME);
authTool.storeAuthInfoInSession(username, validatedAuth.get(CCConstants.AUTH_TICKET), authMethod, session);
CSRFConfig.csrfInitCookie(httpReq,httpResp);
}
} else if (authHdr.length() > 6 && authHdr.substring(0, 6).equalsIgnoreCase("Bearer")) {

Expand Down
Loading

0 comments on commit 930d645

Please sign in to comment.