Search in sources :

Example 11 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.

the class SearchMapper method fromScope.

/**
 * SearchParameters from Scope object
 * @param Scope scope
 * @param sp SearchParameters
 * @param searchRequestContext
 */
public void fromScope(SearchParameters sp, Scope scope, SearchRequestContext searchRequestContext) {
    if (scope != null) {
        List<String> stores = scope.getLocations();
        if (stores != null && !stores.isEmpty()) {
            // First reset the stores then add them.
            sp.getStores().clear();
            searchRequestContext.getStores().addAll(stores);
            for (String aStore : stores) {
                try {
                    sp.addStore(storeMapper.getStoreRef(aStore));
                } catch (AlfrescoRuntimeException are) {
                    throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { aStore });
                }
            }
            if (stores.contains(StoreMapper.HISTORY) && (stores.size() > 1)) {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": scope 'history' can only be used on its own" });
            }
        }
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 12 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.

the class SOLRAuthenticationFilter method doFilter.

public void doFilter(ServletContext context, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    /*		if(secureComms == SecureCommsType.ALFRESCO)
		{
			// Need to get as a byte array because we need to read the request twice, once for authentication
			// and again by the web service.
			SOLRHttpServletRequestWrapper requestWrapper = new SOLRHttpServletRequestWrapper(httpRequest, encryptionUtils);
	
			if(logger.isDebugEnabled())
			{
				logger.debug("Authenticating " + httpRequest.getRequestURI());
			}
	
			if(encryptionUtils.authenticate(httpRequest, requestWrapper.getDecryptedBody()))
			{
				try
				{
					OutputStream out = response.getOutputStream();
	
					GenericResponseWrapper responseWrapper = new GenericResponseWrapper(httpResponse);
	
					// TODO - do I need to chain to other authenticating filters - probably not?
					// Could also remove sending of credentials with http request
					chain.doFilter(requestWrapper, responseWrapper);
	
					Pair<byte[], AlgorithmParameters> pair = encryptor.encrypt(KeyProvider.ALIAS_SOLR, null, responseWrapper.getData());
	
					encryptionUtils.setResponseAuthentication(httpRequest, httpResponse, responseWrapper.getData(), pair.getSecond());

					httpResponse.setHeader("Content-Length", Long.toString(pair.getFirst().length));
					out.write(pair.getFirst());
					out.close();
				}
				catch(Exception e)
				{
					throw new AlfrescoRuntimeException("", e);
				}
			}
			else
			{
				httpResponse.setStatus(401);
			}
		}
		else */
    if (secureComms == SecureCommsType.HTTPS) {
        if (httpRequest.isSecure()) {
            // https authentication
            chain.doFilter(request, response);
        } else {
            throw new AlfrescoRuntimeException("Expected a https request");
        }
    } else {
        chain.doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 13 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.

the class PropFindMethod method generateFindPropertiesResponse.

/**
 * Generates the XML response for a PROPFIND request that asks for a list of
 * all known properties
 *
 * @param xml XMLWriter
 * @param nodeInfo FileInfo
 * @param isDir boolean
 */
protected void generateFindPropertiesResponse(XMLWriter xml, FileInfo nodeInfo, boolean isDir) {
    try {
        // Output the start of the properties element
        Attributes nullAttr = getDAVHelper().getNullAttributes();
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr);
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr);
        // Output the well-known properties
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_LOCK_DISCOVERY));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SUPPORTED_LOCK));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_RESOURCE_TYPE));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_DISPLAYNAME));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_LAST_MODIFIED));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LENGTH));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CREATION_DATE));
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_ETAG));
        if (isDir) {
            xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_LANGUAGE));
            xml.write(DocumentHelper.createElement(WebDAV.XML_NS_GET_CONTENT_TYPE));
        }
        // Output the custom properties
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_ALF_AUTHTICKET));
        // Close off the response
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP);
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr);
        xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT);
    } catch (Exception ex) {
        throw new AlfrescoRuntimeException("XML processing error", ex);
    }
}
Also used : Attributes(org.xml.sax.Attributes) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) InvalidQNameException(org.alfresco.service.namespace.InvalidQNameException) SAXException(org.xml.sax.SAXException)

Example 14 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.

the class PropPatchMethod method generatePropertyResponse.

/**
 * Generates the XML response for a PROPFIND request that asks for a list of
 * all known properties
 *
 * @param xml XMLWriter
 * @param property WebDAVProperty
 * @param status int
 * @param description String
 */
protected void generatePropertyResponse(XMLWriter xml, WebDAVProperty property, int status, String description) {
    try {
        // Output the start of the properties element
        Attributes nullAttr = getDAVHelper().getNullAttributes();
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr);
        // Output property name
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr);
        if (property.hasNamespaceName()) {
            xml.write(DocumentHelper.createElement(property.getNamespaceName() + WebDAV.NAMESPACE_SEPARATOR + property.getName()));
        } else {
            xml.write(DocumentHelper.createElement(property.getName()));
        }
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP);
        // Output action result status
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr);
        xml.write(WebDAV.HTTP1_1 + " " + status + " " + description);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT);
    } catch (Exception ex) {
        // Convert to a runtime exception
        throw new AlfrescoRuntimeException("XML processing error", ex);
    }
}
Also used : Attributes(org.xml.sax.Attributes) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 15 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method getSiteInvitation.

private Invitation getSiteInvitation(String inviteeId, String siteId) {
    // Is there an outstanding site invite request for the invitee?
    InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl();
    criteria.setInvitationType(InvitationType.MODERATED);
    criteria.setInvitee(inviteeId);
    criteria.setResourceName(siteId);
    criteria.setResourceType(ResourceType.WEB_SITE);
    List<Invitation> invitations = invitationService.searchInvitation(criteria);
    if (invitations.size() > 1) {
        // TODO exception
        throw new AlfrescoRuntimeException("There should be only one outstanding site invitation");
    }
    return (invitations.size() == 0 ? null : invitations.get(0));
}
Also used : ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) InvitationSearchCriteriaImpl(org.alfresco.repo.invitation.InvitationSearchCriteriaImpl) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8