Skip to content

Commit

Permalink
deps: removing/replacing esup-commons old library
Browse files Browse the repository at this point in the history
  • Loading branch information
jgribonvald committed Oct 10, 2022
1 parent 5adde6c commit bea9a72
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 132 deletions.
51 changes: 4 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,51 +143,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.esupportail</groupId>
<artifactId>esup-commons2-web</artifactId>
<version>0.2.8</version>
<exclusions>
<exclusion>
<artifactId>
jsr168forwardport.org.springframework.web.portlet
</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>esup-uportal-ws-client</artifactId>
<groupId>esup</groupId>
</exclusion>
<exclusion>
<artifactId>spring-context-support</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>spring-test</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>rome</artifactId>
<groupId>rome</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Provides the PortalPropertySourcesPlaceholderConfigurer
that supports global.properties and Jasypt encryption-->
<dependency>
Expand Down Expand Up @@ -225,9 +180,11 @@
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.esupportail</groupId>
<artifactId>esup-commons2-web</artifactId>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
<version>2.3.9</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,40 @@
*/
package org.esupportail.portlet.filemanager.exceptions;

import org.esupportail.commons.exceptions.EsupException;

public class EsupStockException extends EsupException {

protected String codeI18n = "exception.general";

public EsupStockException(Exception e) {
super(e);
}

public EsupStockException(String message) {
super(message);
}

public EsupStockException(String message, String codeI18n) {
super(message);
this.codeI18n = codeI18n;
}

public EsupStockException(String message, Exception e) {
super(message, e);
}

public String getRootCause() {
Throwable t = this;
while(t.getCause() != null)
t = t.getCause();
return t.getMessage();
}

public String getCodeI18n() {
return codeI18n;
}



private static final long serialVersionUID = 1L;

public class EsupStockException extends RuntimeException {

protected String codeI18n = "exception.general";

public EsupStockException(Exception e) {
super(e);
}

public EsupStockException(String message) {
super(message);
}

public EsupStockException(String message, String codeI18n) {
super(message);
this.codeI18n = codeI18n;
}

public EsupStockException(String message, Exception e) {
super(message, e);
}

public String getRootCause() {
Throwable t = this;
while(t.getCause() != null)
t = t.getCause();
return t.getMessage();
}

public String getCodeI18n() {
return codeI18n;
}



private static final long serialVersionUID = 1L;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.esupportail.portlet.filemanager.services.opencmis;

import org.esupportail.portlet.filemanager.exceptions.EsupStockNoRequestBoundException;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.portlet.context.PortletRequestAttributes;

public class ContextUtils {

/**
* @param name
* @return The attribute that corresponds to a name.
*/
public static Object getSessionAttribute(final String name) {
return getContextAttribute(name, RequestAttributes.SCOPE_SESSION);
}

/**
* Set a session attribute.
* @param name
* @param value
*/
public static void setSessionAttribute(
final String name,
final Object value) {
setContextAttribute(name, value, RequestAttributes.SCOPE_SESSION);
}

/**
* @return The request attributes.
* @throws EsupStockNoRequestBoundException
*/
static RequestAttributes getContextAttributes() throws EsupStockNoRequestBoundException {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
throw new EsupStockNoRequestBoundException();
}
if (!(requestAttributes instanceof ServletRequestAttributes)
&& !(requestAttributes instanceof PortletRequestAttributes)) {
throw new IllegalArgumentException(
"requestAttributes of unknown class [" + requestAttributes.getClass() + "]");
}
return requestAttributes;
}

/**
* Set an attribute for a given scope.
* @param name
* @param value
* @param scope
*/
private static void setContextAttribute(
final String name,
final Object value,
final int scope) {
getContextAttributes().setAttribute(name, value, scope);
}

/**
* @param name
* @param scope
* @return The value of the attribute for a given scope.
*/
private static Object getContextAttribute(
final String name,
final int scope) {
return getContextAttributes().getAttribute(name, scope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.Map;
import java.util.Random;

import net.iharder.Base64;
import org.apache.chemistry.opencmis.client.bindings.spi.AbstractAuthenticationProvider;
import org.esupportail.commons.utils.Base64;

public class NuxeoPortalSSOAuthenticationProvider extends AbstractAuthenticationProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,28 @@
import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.esupportail.commons.utils.ContextUtils;
import org.esupportail.portlet.filemanager.beans.SharedUserPortletParameters;
import org.esupportail.portlet.filemanager.beans.UserPassword;

public class TrustedCmisAccessImpl extends CmisAccessImpl {

protected static final Log log = LogFactory.getLog(TrustedCmisAccessImpl.class);

protected Map<String, String> userinfosHttpheadersMap;

protected Map<String, String> staticHttpheadersMap;

protected Map<String, String> userinfosHttpheadersValues;

protected String nuxeoPortalSsoSecretKey;

protected String nuxeoPortalSsoUsernameAttribute;

public void setUserinfosHttpheadersMap(
Map<String, String> userinfosHttpheadersMap) {
this.userinfosHttpheadersMap = userinfosHttpheadersMap;
}

public void setStaticHttpheadersMap(Map<String, String> staticHttpheadersMap) {
this.staticHttpheadersMap = staticHttpheadersMap;
}
Expand All @@ -67,15 +66,15 @@ public void setNuxeoPortalSsoUsernameAttribute(

@Override
protected void manipulateUri(Map userInfos, String username) {

// useful to test in servlet mode : in userinfosHttpheadersValues we set directly shib attributes values
if(staticHttpheadersMap!=null) {
userinfosHttpheadersValues = new HashMap<String, String>();
userinfosHttpheadersValues = new HashMap<String, String>();
for(String key : staticHttpheadersMap.keySet()) {
userinfosHttpheadersValues.put(key, staticHttpheadersMap.get(key));
}
}

// goal is to get shibboleth attributes from portal via userInfos
if(userinfosHttpheadersMap!=null & userInfos != null) {
userinfosHttpheadersValues = new HashMap<String, String>();
Expand All @@ -84,14 +83,14 @@ protected void manipulateUri(Map userInfos, String username) {
userinfosHttpheadersValues.put(key, userInfoValue);
}
}

super.manipulateUri(userInfos, username);
}


@Override
public void open(SharedUserPortletParameters userParameters) {

if(!this.isOpened()) {
manipulateUri(userParameters.getUserInfos(), null);
if(this.userAuthenticatorService != null)
Expand All @@ -101,16 +100,16 @@ public void open(SharedUserPortletParameters userParameters) {

parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB
.value());

parameters.put(SessionParameter.ATOMPUB_URL, uri);
parameters.put(SessionParameter.REPOSITORY_ID, respositoryId);

if(userAuthenticatorService != null) {
UserPassword userPassword = userAuthenticatorService.getUserPassword(userParameters);
parameters.put(SessionParameter.USER, userPassword.getUsername());
parameters.put(SessionParameter.PASSWORD, userPassword.getPassword());
}

if(userinfosHttpheadersValues != null) {
parameters.put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS, TrustedHttpheadersCmisAuthenticationProvider.class.getName());
Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
Expand All @@ -120,21 +119,21 @@ public void open(SharedUserPortletParameters userParameters) {
httpHeaders.put(key, values);
}
ContextUtils.setSessionAttribute(TrustedHttpheadersCmisAuthenticationProvider.ESUP_HEADER_SHIB_HTTP_HEADERS, httpHeaders);
}
}
if(nuxeoPortalSsoSecretKey != null && nuxeoPortalSsoUsernameAttribute!=null) {
parameters.put(NuxeoPortalSSOAuthenticationProvider.SECRET_KEY, nuxeoPortalSsoSecretKey);
parameters.put(NuxeoPortalSSOAuthenticationProvider.SECRET_KEY, nuxeoPortalSsoSecretKey);
parameters.put(SessionParameter.AUTHENTICATION_PROVIDER_CLASS, NuxeoPortalSSOAuthenticationProvider.class.getName());

String username = (String)userParameters.getUserInfos().get(nuxeoPortalSsoUsernameAttribute);
parameters.put(SessionParameter.USER, username);
}

try {
cmisSession = SessionFactoryImpl.newInstance().createSession(parameters);
cmisSession = SessionFactoryImpl.newInstance().createSession(parameters);
} catch(CmisConnectionException ce) {
log.warn("failed to retriev cmisSession : " + uri + " , repository is not accessible or simply not started ?", ce);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@
*/
package org.esupportail.portlet.filemanager.services.opencmis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.chemistry.opencmis.client.bindings.spi.AbstractAuthenticationProvider;
import org.apache.chemistry.opencmis.client.bindings.spi.StandardAuthenticationProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.esupportail.commons.utils.ContextUtils;
import org.springframework.web.context.request.RequestContextHolder;



public class TrustedHttpheadersCmisAuthenticationProvider extends AbstractAuthenticationProvider {

private static final long serialVersionUID = 1L;

protected static final Log log = LogFactory.getLog(TrustedHttpheadersCmisAuthenticationProvider.class);

public static final String ESUP_HEADER_SHIB_HTTP_HEADERS = "ESUP_HEADER_SHIB_HTTP_HEADERS";

@Override
public Map<String, List<String>> getHTTPHeaders(String url) {
Map<String, List<String>> httpHeaders = null;
Expand Down
Loading

0 comments on commit bea9a72

Please sign in to comment.