mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.webservice.axis;
|
||||
|
||||
import org.alfresco.repo.webservice.Utils;
|
||||
import org.alfresco.repo.webservice.types.QueryConfiguration;
|
||||
import org.apache.axis.AxisFault;
|
||||
import org.apache.axis.MessageContext;
|
||||
import org.apache.axis.description.OperationDesc;
|
||||
import org.apache.axis.handlers.BasicHandler;
|
||||
import org.apache.axis.message.SOAPEnvelope;
|
||||
import org.apache.axis.message.SOAPHeaderElement;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Axis handler to extract the fetchSize parameter from the QueryConfiguration SOAP header.
|
||||
* The value of fetchSize is then placed in the MessageContext with a property name of
|
||||
* ALF_FETCH_SIZE
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class QueryConfigHandler extends BasicHandler
|
||||
{
|
||||
public static final String ALF_FETCH_SIZE = "ALF_FETCH_SIZE";
|
||||
|
||||
private static final long serialVersionUID = 6467938074555362971L;
|
||||
private static Log logger = LogFactory.getLog(QueryConfigHandler.class);
|
||||
|
||||
/**
|
||||
* @see org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)
|
||||
*/
|
||||
public void invoke(MessageContext msgContext) throws AxisFault
|
||||
{
|
||||
try
|
||||
{
|
||||
// determine the method we are calling
|
||||
String opName = "Unknown method";
|
||||
OperationDesc op = msgContext.getOperation();
|
||||
if (op != null)
|
||||
{
|
||||
opName = op.getName();
|
||||
}
|
||||
|
||||
// try and find the appropriate header and extract info from it
|
||||
SOAPEnvelope env = msgContext.getRequestMessage().getSOAPEnvelope();
|
||||
SOAPHeaderElement header = env.getHeaderByName(Utils.REPOSITORY_SERVICE_NAMESPACE, "QueryHeader");
|
||||
if (header != null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Found QueryHeader for call to " + opName);
|
||||
|
||||
QueryConfiguration queryCfg = (QueryConfiguration)header.getObjectValue(QueryConfiguration.class);
|
||||
if (queryCfg != null)
|
||||
{
|
||||
int fetchSize = queryCfg.getFetchSize();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Fetch size for query = " + fetchSize);
|
||||
|
||||
msgContext.setProperty(ALF_FETCH_SIZE, new Integer(fetchSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Failed to find QueryConfiguration within QueryHeader");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("QueryHeader was not found for call to " + opName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Failed to determine fetch size", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.webservice.axis;
|
||||
|
||||
import org.alfresco.repo.webservice.Utils;
|
||||
import org.apache.axis.AxisFault;
|
||||
import org.apache.axis.MessageContext;
|
||||
import org.apache.axis.handlers.soap.SOAPService;
|
||||
import org.apache.axis.providers.java.RPCProvider;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
/**
|
||||
* A custom Axis RPC Provider that retrieves services via Spring
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class SpringBeanRPCProvider extends RPCProvider
|
||||
{
|
||||
private static final long serialVersionUID = 2173234269124176995L;
|
||||
private static final String OPTION_NAME = "springBean";
|
||||
private WebApplicationContext webAppCtx;
|
||||
|
||||
/**
|
||||
* Retrieves the class of the bean represented by the given name
|
||||
*
|
||||
* @see org.apache.axis.providers.java.JavaProvider#getServiceClass(java.lang.String, org.apache.axis.handlers.soap.SOAPService, org.apache.axis.MessageContext)
|
||||
*/
|
||||
@Override
|
||||
protected Class getServiceClass(String beanName, SOAPService service, MessageContext msgCtx) throws AxisFault
|
||||
{
|
||||
Class clazz = null;
|
||||
|
||||
Object bean = getBean(msgCtx, beanName);
|
||||
if (bean != null)
|
||||
{
|
||||
clazz = bean.getClass();
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.axis.providers.java.JavaProvider#getServiceClassNameOptionName()
|
||||
*/
|
||||
@Override
|
||||
protected String getServiceClassNameOptionName()
|
||||
{
|
||||
return OPTION_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the bean with the given name from the current spring context
|
||||
*
|
||||
* @see org.apache.axis.providers.java.JavaProvider#makeNewServiceObject(org.apache.axis.MessageContext, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected Object makeNewServiceObject(MessageContext msgCtx, String beanName) throws Exception
|
||||
{
|
||||
return getBean(msgCtx, beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the bean with the given name from the current spring context
|
||||
*
|
||||
* @param msgCtx Axis MessageContext
|
||||
* @param beanName Name of the bean to lookup
|
||||
* @return The instance of the bean
|
||||
*/
|
||||
private Object getBean(MessageContext msgCtx, String beanName) throws AxisFault
|
||||
{
|
||||
return getWebAppContext(msgCtx).getBean(beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Spring context from the web application
|
||||
*
|
||||
* @param msgCtx Axis MessageContext
|
||||
* @return The Spring web app context
|
||||
*/
|
||||
private WebApplicationContext getWebAppContext(MessageContext msgCtx) throws AxisFault
|
||||
{
|
||||
if (this.webAppCtx == null && msgCtx != null)
|
||||
{
|
||||
this.webAppCtx = Utils.getSpringContext(msgCtx);
|
||||
}
|
||||
|
||||
if (this.webAppCtx == null)
|
||||
{
|
||||
throw new AxisFault("Failed to retrieve the Spring web application context");
|
||||
}
|
||||
|
||||
return this.webAppCtx;
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.webservice.axis;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.webservice.authentication.AuthenticationFault;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ws.security.WSPasswordCallback;
|
||||
|
||||
/**
|
||||
* CallbackHandler that verifies the given ticket in the password element of the UsernameToken
|
||||
* header is still a valid ticket
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TicketCallbackHandler implements CallbackHandler
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(TicketCallbackHandler.class);
|
||||
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
/**
|
||||
* Sets the AuthenticationService instance to use
|
||||
*
|
||||
* @param authenticationService The AuthenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
|
||||
*/
|
||||
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
|
||||
{
|
||||
for (int i = 0; i < callbacks.length; i++)
|
||||
{
|
||||
if (callbacks[i] instanceof WSPasswordCallback)
|
||||
{
|
||||
WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
|
||||
String ticket = pc.getPassword();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Verifying ticket for: " + pc.getIdentifer());
|
||||
logger.debug("Ticket: " + ticket);
|
||||
}
|
||||
|
||||
// ensure the ticket is valid
|
||||
try
|
||||
{
|
||||
this.authenticationService.validate(ticket);
|
||||
}
|
||||
catch (AuthenticationException ae)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Ticket validation failed: " + ae.getMessage());
|
||||
|
||||
// NOTE: Throwing AuthenticationFault just gets consumed and the ws-security handler
|
||||
// reports a missing password; we would need to modify the WSS4J code to let
|
||||
// the exception bubble up so for now just let the default message get thrown
|
||||
throw new AuthenticationFault(701, "Authentication failed due to an invalid ticket");
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Ticket validated successfully");
|
||||
|
||||
// if all is well set the password to return as the given ticket
|
||||
pc.setPassword(pc.getPassword());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.webservice.axis;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.axis.AxisFault;
|
||||
import org.apache.axis.MessageContext;
|
||||
import org.apache.axis.handlers.BasicHandler;
|
||||
import org.apache.axis.transport.http.HTTPConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.ws.security.handler.WSHandlerConstants;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
/**
|
||||
* Axis handler that retrieves the TicketCallbackHandler instance from
|
||||
* a Spring context. The authentication service is injected by Spring
|
||||
* so that when it gets called by the WSS4J handler it can verify the
|
||||
* ticket passed to the service.
|
||||
* The callback handler is then added to the MessageContext under the standard
|
||||
* WsHandlerConstants.PW_CALLBACK_REF property.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TicketCallbackSpringHandler extends BasicHandler
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(TicketCallbackSpringHandler.class);
|
||||
private static final String BEAN_NAME = "ticketCallbackHandler";
|
||||
private static final long serialVersionUID = -135125831180499667L;
|
||||
|
||||
/**
|
||||
* @see org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)
|
||||
*/
|
||||
public void invoke(MessageContext msgContext) throws AxisFault
|
||||
{
|
||||
// get hold of the Spring context and retrieve the AuthenticationService
|
||||
HttpServletRequest req = (HttpServletRequest)msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
|
||||
ServletContext servletCtx = req.getSession().getServletContext();
|
||||
WebApplicationContext webAppCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
|
||||
TicketCallbackHandler callback = (TicketCallbackHandler)webAppCtx.getBean(BEAN_NAME);
|
||||
|
||||
// store the callback in the context where the WS-Security handler can pick it up from
|
||||
msgContext.setProperty(WSHandlerConstants.PW_CALLBACK_REF, callback);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.webservice.axis;
|
||||
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.Handler;
|
||||
import org.apache.axis.deployment.wsdd.WSDDProvider;
|
||||
import org.apache.axis.deployment.wsdd.WSDDService;
|
||||
|
||||
/**
|
||||
* Provider class loaded by Axis, used to identify and
|
||||
* create an instance of our SpringRPC provider which in
|
||||
* turn loads service endpoints from Spring configured beans
|
||||
*
|
||||
* @see org.alfresco.repo.webservice.axis.SpringBeanRPCProvider
|
||||
* @author gavinc
|
||||
*/
|
||||
public class WSDDSpringBeanRPCProvider extends WSDDProvider
|
||||
{
|
||||
private static final String PROVIDER_NAME = "SpringRPC";
|
||||
|
||||
/**
|
||||
* @see org.apache.axis.deployment.wsdd.WSDDProvider#newProviderInstance(org.apache.axis.deployment.wsdd.WSDDService, org.apache.axis.EngineConfiguration)
|
||||
*/
|
||||
@Override
|
||||
public Handler newProviderInstance(WSDDService service, EngineConfiguration registry)
|
||||
throws Exception
|
||||
{
|
||||
return new SpringBeanRPCProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.axis.deployment.wsdd.WSDDProvider#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return PROVIDER_NAME;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user