Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/8.3' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/8.3
  • Loading branch information
metaventis-build committed Apr 30, 2024
2 parents 25c97cf + d02b7dc commit 6ae3ff6
Show file tree
Hide file tree
Showing 75 changed files with 967 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableSet;

public class CCConstants {

Expand Down Expand Up @@ -1964,14 +1965,14 @@ public static ArrayList<String> getPermissionList(){
return permission;
}

private static ArrayList<String> usagePermissions = null;
private static HashSet<String> usagePermissions = null;
/**
* Permissions allowed if the node was opened via usage (lms) or signature
* @return
*/
public static synchronized List<String> getUsagePermissions(){
public static synchronized Set<String> getUsagePermissions(){
if(usagePermissions == null){
usagePermissions = new ArrayList<>();
usagePermissions = new HashSet<>();
usagePermissions.add(PERMISSION_READ);
usagePermissions.add(PERMISSION_READ_PREVIEW);
usagePermissions.add(PERMISSION_READ_ALL);
Expand All @@ -1980,7 +1981,7 @@ public static synchronized List<String> getUsagePermissions(){
usagePermissions.add(PERMISSION_RATE);
usagePermissions.add(PERMISSION_RATE_READ);
}
return unmodifiableList(usagePermissions);
return unmodifiableSet(usagePermissions);
}

//AuthorityTypeKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
ArchiveInputStream zip = getZipInputStream(contentreader);
ArchiveEntry current = null;
if(zip!=null) {
boolean genericHtmlFallback = false;
while ((current = zip.getNextEntry()) != null) {
if (current.getName().equals("imsmanifest.xml")) {

Expand All @@ -115,9 +116,7 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {

}
if (current.getName().equalsIgnoreCase("index.html") || current.getName().equalsIgnoreCase("index.htm")) {
zip.close();
proccessGenericHTML(actionedUponNodeRef);
return;
genericHtmlFallback = true;
}

if (current.getName().equals("moodle.xml")) {
Expand Down Expand Up @@ -145,6 +144,9 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
}

zip.close();
if(genericHtmlFallback){
proccessGenericHTML(actionedUponNodeRef);
}
} else {
if(Arrays.asList("application/json", "text/plain", "application/octet-stream").contains(contentreader.getMimetype()) &&
contentreader.getSize() < MAX_JSON_PARSE_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Register implements Serializable {
@XmlElement public Boolean recoverPassword;
@XmlElement public String loginUrl;
@XmlElement public String recoverUrl;
@XmlElement public String recoverUrlSafe;
@XmlElement public List<String> requiredFields;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ public class Rendering implements Serializable {
@XmlElement public Boolean showPreview;
@XmlElement public Boolean showDownloadButton;
@XmlElement public Boolean prerender;
@XmlElement public RenderingGdpr[] gdpr;

public static class RenderingGdpr implements Serializable {
@XmlElement public String matcher;
@XmlElement public String name;
@XmlElement public String privacyInformationUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.drew.metadata.MetadataException;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.sun.star.uno.Exception;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.apache.tika.config.TikaConfig;
import org.apache.tika.detect.Detector;
import org.apache.tika.io.TikaInputStream;
Expand All @@ -20,7 +23,7 @@
import java.awt.image.BufferedImage;
import java.io.*;

/**
/**
*
* @author Torsten
* Tool for common image tasks like rotating by exif orientation
Expand Down Expand Up @@ -145,18 +148,30 @@ private static BufferedImage scaleImage(BufferedImage image, int maxSize) {

/**
* checks if given input stream is an image mimetype and throws an exception otherwise
* Will also auto convert svg to remove malicious data and auto rotate jpgs based on exif data
*/
public static InputStream verifyImage(InputStream is) throws MimeTypeException, IOException {
byte[] data=org.apache.poi.util.IOUtils.toByteArray(is);
public static VerifyResult verifyAndPreprocessImage(InputStream is, int maxSize) throws MimeTypeException, IOException {
byte[] data= IOUtils.toByteArray(is);
TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
TikaInputStream stream = TikaInputStream.get(data);
Metadata metadata = new Metadata();
MediaType mediaType = detector.detect(stream, metadata);
if(!mediaType.getType().equals("image")) {
if(!mediaType.getType().equals("image") && !mediaType.getType().equals("text")) {
// TODO: convert to NodeMimetypeValidationException after merge of file filter completed
throw new MimeTypeException("Invalid mime type for image: " + mediaType.getType() + "/" + mediaType.getSubtype());
}
return new ByteArrayInputStream(data);
if(mediaType.getType().equals("text") || mediaType.equals(MediaType.image("svg+xml"))) {
throw new MimeTypeException("svg is currently not supported");
}
InputStream result = autoRotateImage(new java.io.ByteArrayInputStream(data), ImageTool.MAX_THUMB_SIZE);
return new VerifyResult(result, mediaType);
}

@Data
@AllArgsConstructor
public static class VerifyResult {
InputStream inputStream;
MediaType mediaType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.typesafe.config.Config;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
Expand All @@ -46,9 +47,10 @@


public class Mail {


public static String AUTH_TYPE_TLS = "tls";
public static String AUTH_TYPE_SSL = "ssl";
private org.apache.log4j.Category logger = null;

private Config configSMTP = null;
Expand All @@ -64,39 +66,48 @@ public Mail() {
}
}

private void sendMail(String sender, String senderName, String receiver, String subject, String message) throws EmailException {
logger.info("start mailing sender:" + sender + " receiver" + receiver + " message" + message);
private void setEmailSettings(Email email){


String mailServer = configSMTP.getString("host");
int smtpPort = configSMTP.getInt("port");
String username = configSMTP.getString("username");
String password = configSMTP.getString("password");
String authType = configSMTP.getString("authtype");
logger.info("mailServer:" + mailServer + " smtpPort:" + smtpPort + "username:" + username + "password:" + password);
SimpleEmail email = new SimpleEmail();




email.setCharset("utf-8");

email.setDebug(true);
email.setHostName(mailServer);
email.setSmtpPort((int) smtpPort);

if(authType != null && !authType.trim().equals("")){
if(authType.trim().equals(AUTH_TYPE_TLS)){
email.setTLS(true);
email.setSmtpPort(smtpPort);

if(StringUtils.isNotBlank(authType)){
if(authType.trim().toLowerCase().equals(AUTH_TYPE_TLS)){
email.setStartTLSEnabled(true);
}else if(authType.trim().toLowerCase().equals(AUTH_TYPE_SSL)) {
email.setSSLOnConnect(true);
email.setSslSmtpPort(Integer.toString(smtpPort));
}else{
logger.info("auth type "+authType +" not supported at the moment");
}
}



if ((username != null && password != null) && (!username.trim().equals("") && !password.trim().equals(""))) {
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
logger.info("email.setAuthentication()");
email.setAuthentication(username, password);
}



}

private void sendMail(String sender, String senderName, String receiver, String subject, String message) throws EmailException {
logger.info("start mailing sender:" + sender + " receiver" + receiver + " message" + message);

SimpleEmail email = new SimpleEmail();
setEmailSettings(email);

try{
logger.info("start sending mail...");
logger.info("sender:" + sender);
Expand All @@ -109,7 +120,7 @@ private void sendMail(String sender, String senderName, String receiver, String
}else{
email.setFrom(sender);
}

email.addTo(receiver);
email.setSubject(subject);
email.setMsg(message);
Expand All @@ -123,43 +134,14 @@ private void sendMail(String sender, String senderName, String receiver, String
logger.error("message:" + message);
logger.error("Exception Message:" + e.getMessage());
}else throw e;

}


}

private void sendMailHtml(ServletContext context, String sender, String senderName, String replyTo, String receiver, String subject, String message) throws EmailException {
logger.info("start mailing sender:" + sender + " receiver" + receiver + " message" + message);

String mailServer = configSMTP.getString("host");
int smtpPort = configSMTP.getInt("port");
String username = configSMTP.getString("username");
String password = configSMTP.getString("password");
String authType = configSMTP.getString("authtype");
logger.info("mailServer:" + mailServer + " smtpPort:" + smtpPort + "username:" + username + "password:" + password);
HtmlEmail email = new HtmlEmail();


email.setCharset("utf-8");

email.setDebug(false);
email.setHostName(mailServer);
email.setSmtpPort((int) smtpPort);

if(authType != null && !authType.trim().equals("")){
if(authType.toLowerCase().trim().equals(AUTH_TYPE_TLS)){
email.setTLS(true);
}else{
logger.info("auth type "+authType +" not supported at the moment");
}
}


setEmailSettings(email);

if ((username != null && password != null) && (!username.trim().equals("") && !password.trim().equals(""))) {
logger.debug("email.setAuthentication()");
email.setAuthentication(username, password);
}
try{
logger.info("start sending mail...");
logger.debug("sender:" + sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.typesafe.config.Config;
import org.alfresco.repo.web.filter.beans.DependencyInjectedFilter;
import org.alfresco.repo.webdav.auth.LDAPAuthenticationFilter;
import org.edu_sharing.alfresco.lightbend.LightbendConfigLoader;
import org.edu_sharing.alfrescocontext.gate.AlfAppContextGate;
import org.edu_sharing.spring.ApplicationContextFactory;

public class Edu_SharingBeanProxyFilter implements Filter
{
Expand All @@ -21,7 +25,13 @@ public class Edu_SharingBeanProxyFilter implements Filter
private static final String INIT_PARAM_BEAN_NAME = "beanName";

private DependencyInjectedFilter filter;
private ServletContext context;
private ServletContext context;

Config eduConfig = LightbendConfigLoader.get();

static String CONFIG_ENABLED = "repository.webdav.enabled";

boolean enabled = true;

/**
* Initialize the filter.
Expand All @@ -34,8 +44,14 @@ public class Edu_SharingBeanProxyFilter implements Filter
*/
public void init(FilterConfig args) throws ServletException
{
this.filter = (DependencyInjectedFilter)AlfAppContextGate.getApplicationContext().getBean(args.getInitParameter(INIT_PARAM_BEAN_NAME));
if(eduConfig.hasPath(CONFIG_ENABLED)){
enabled = eduConfig.getBoolean(CONFIG_ENABLED);
}
this.context = args.getServletContext();
this.filter = (DependencyInjectedFilter) ApplicationContextFactory.getApplicationContext().getBean(args.getInitParameter(INIT_PARAM_BEAN_NAME));
if(this.filter instanceof Filter){
((Filter)this.filter).init(args);
}
}

/* (non-Javadoc)
Expand All @@ -52,7 +68,7 @@ public void destroy()
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException
{
this.filter.doFilter(this.context, request, response, chain);
if(enabled) this.filter.doFilter(this.context, request, response, chain);
}

}
Loading

0 comments on commit 6ae3ff6

Please sign in to comment.