mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge pull request #64 from Alfresco/feature/repo-3428_remove_portletapi
REPO-3428: EOL Library JSR-168 Portlets API
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -125,11 +125,6 @@
|
|||||||
<artifactId>commons-csv</artifactId>
|
<artifactId>commons-csv</artifactId>
|
||||||
<version>20110211</version>
|
<version>20110211</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javax.portlet</groupId>
|
|
||||||
<artifactId>portlet-api</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.alfresco.surf</groupId>
|
<groupId>org.alfresco.surf</groupId>
|
||||||
<artifactId>spring-webscripts</artifactId>
|
<artifactId>spring-webscripts</artifactId>
|
||||||
|
@@ -1,186 +0,0 @@
|
|||||||
/*
|
|
||||||
* #%L
|
|
||||||
* Alfresco Remote API
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
|
||||||
* %%
|
|
||||||
* This file is part of the Alfresco software.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* #L%
|
|
||||||
*/
|
|
||||||
package org.alfresco.repo.web.scripts.portlet;
|
|
||||||
|
|
||||||
import javax.portlet.RenderRequest;
|
|
||||||
import javax.portlet.RenderResponse;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.transaction.UserTransaction;
|
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
|
||||||
import org.springframework.extensions.webscripts.Authenticator;
|
|
||||||
import org.springframework.extensions.webscripts.WebScriptException;
|
|
||||||
import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
|
|
||||||
import org.springframework.extensions.webscripts.portlet.PortletAuthenticatorFactory;
|
|
||||||
import org.springframework.extensions.webscripts.portlet.WebScriptPortletRequest;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Portlet authenticator
|
|
||||||
*
|
|
||||||
* @author davidc
|
|
||||||
*/
|
|
||||||
public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFactory
|
|
||||||
{
|
|
||||||
// Logger
|
|
||||||
private static final Log logger = LogFactory.getLog(JSR168PortletAuthenticatorFactory.class);
|
|
||||||
|
|
||||||
// dependencies
|
|
||||||
private AuthenticationService unprotAuthenticationService;
|
|
||||||
private TransactionService txnService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param authenticationService AuthenticationService
|
|
||||||
*/
|
|
||||||
public void setUnprotAuthenticationService(AuthenticationService authenticationService)
|
|
||||||
{
|
|
||||||
this.unprotAuthenticationService = authenticationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param transactionService TransactionService
|
|
||||||
*/
|
|
||||||
public void setTransactionService(TransactionService transactionService)
|
|
||||||
{
|
|
||||||
this.txnService = transactionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.portlet.PortletAuthenticatorFactory#create(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
|
|
||||||
*/
|
|
||||||
public Authenticator create(RenderRequest req, RenderResponse res)
|
|
||||||
{
|
|
||||||
return new JSR168PortletAuthenticator(req, res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Portlet authenticator
|
|
||||||
*
|
|
||||||
* @author davidc
|
|
||||||
*/
|
|
||||||
public class JSR168PortletAuthenticator implements Authenticator
|
|
||||||
{
|
|
||||||
// dependencies
|
|
||||||
private RenderRequest req;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct
|
|
||||||
*
|
|
||||||
* @param req RenderRequest
|
|
||||||
* @param res RenderResponse
|
|
||||||
*/
|
|
||||||
public JSR168PortletAuthenticator(RenderRequest req, RenderResponse res)
|
|
||||||
{
|
|
||||||
this.req = req;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*(non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.Authenticator#authenticate(org.alfresco.web.scripts.Description.RequiredAuthentication, boolean)
|
|
||||||
*/
|
|
||||||
public boolean authenticate(RequiredAuthentication required, boolean isGuest)
|
|
||||||
{
|
|
||||||
// first look for the username key in the session - we add this by hand for some portals
|
|
||||||
// when the WebScriptPortletRequest is created
|
|
||||||
String portalUser = (String)req.getPortletSession().getAttribute(WebScriptPortletRequest.ALFPORTLETUSERNAME);
|
|
||||||
if (portalUser == null)
|
|
||||||
{
|
|
||||||
portalUser = req.getRemoteUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("JSR-168 Remote user: " + portalUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGuest || portalUser == null)
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
logger.debug("Authenticating as Guest");
|
|
||||||
|
|
||||||
// authenticate as guest
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
logger.debug("Authenticating as user " + portalUser);
|
|
||||||
|
|
||||||
UserTransaction txn = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
txn = txnService.getUserTransaction();
|
|
||||||
txn.begin();
|
|
||||||
|
|
||||||
if (!unprotAuthenticationService.authenticationExists(portalUser))
|
|
||||||
{
|
|
||||||
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
|
|
||||||
}
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(portalUser);
|
|
||||||
}
|
|
||||||
catch (Throwable err)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Error authenticating user: " + portalUser, err);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (txn != null)
|
|
||||||
{
|
|
||||||
txn.rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception tex)
|
|
||||||
{
|
|
||||||
// nothing useful we can do with this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.alfresco.web.scripts.Authenticator#emptyCredentials()
|
|
||||||
*/
|
|
||||||
public boolean emptyCredentials()
|
|
||||||
{
|
|
||||||
String portalUser = (String)req.getPortletSession().getAttribute(WebScriptPortletRequest.ALFPORTLETUSERNAME);
|
|
||||||
if (portalUser == null)
|
|
||||||
{
|
|
||||||
portalUser = req.getRemoteUser();
|
|
||||||
}
|
|
||||||
return (portalUser == null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -218,12 +218,6 @@
|
|||||||
<property name="authenticationListener" ref="webScriptAuthenticationListener"/>
|
<property name="authenticationListener" ref="webScriptAuthenticationListener"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- JSR-168 Authenticator (Portal based) -->
|
|
||||||
<bean id="webscripts.authenticator.jsr168" class="org.alfresco.repo.web.scripts.portlet.JSR168PortletAuthenticatorFactory" lazy-init="true">
|
|
||||||
<property name="unprotAuthenticationService" ref="authenticationService" />
|
|
||||||
<property name="transactionService" ref="TransactionService" />
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
<!-- API Beans -->
|
<!-- API Beans -->
|
||||||
|
Reference in New Issue
Block a user