Java Code Examples for org.alfresco.util.ParameterCheck#mandatoryString()

The following examples show how to use org.alfresco.util.ParameterCheck#mandatoryString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 ** SearchParameters from List<FacetQuery>
 * @param sp
 * @param facetQueries
 */
public void fromFacetQuery(SearchParameters sp, List<FacetQuery> facetQueries)
{
    if (facetQueries != null && !facetQueries.isEmpty())
    {
        for (FacetQuery fq:facetQueries)
        {
            ParameterCheck.mandatoryString("facetQuery query", fq.getQuery());
            String query = fq.getQuery();
            String label = fq.getLabel()!=null?fq.getLabel():query;

            if (query.startsWith("{!afts"))
            {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                            new Object[] { ": Facet queries should not start with !afts" });
            }
            query = "{!afts key='"+label+"'}"+query;
            sp.addFacetQuery(query);
        }
    }
}
 
Example 2
Source File: CompositePasswordEncoder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Does the password match?
 * @param rawPassword  mandatory password
 * @param encodedPassword mandatory hashed version
 * @param salt optional salt
 * @param encodingChain mandatory encoding chain
 * @return true if they match
 */
public boolean matchesPassword(String rawPassword, String encodedPassword, Object salt, List<String> encodingChain)
{
    ParameterCheck.mandatoryString("rawPassword", rawPassword);
    ParameterCheck.mandatoryString("encodedPassword", encodedPassword);
    ParameterCheck.mandatoryCollection("encodingChain", encodingChain);
    if (encodingChain.size() > 1)
    {
        String lastEncoder = encodingChain.get(encodingChain.size() - 1);
        String encoded = encodePassword(rawPassword,salt, encodingChain.subList(0,encodingChain.size()-1));
        return matches(lastEncoder,encoded,encodedPassword,salt);
    }

    if (encodingChain.size() == 1)
    {
        return matches(encodingChain.get(0), rawPassword, encodedPassword, salt);
    }
    return false;
}
 
Example 3
Source File: Authorization.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Construct
 * 
 * @param authorization String
 */
public Authorization(String authorization)
{
    ParameterCheck.mandatoryString("authorization", authorization);
    if (authorization.length() == 0)
    {
        throw new IllegalArgumentException("authorization does not consist of username and password");
    }

    int idx = authorization.indexOf(':');

    if (idx == -1)
    {
        setUser(null, authorization);
    }
    else
    {
        setUser(authorization.substring(0, idx), authorization.substring(idx + 1));
    }
}
 
Example 4
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * SearchParameters from the Query object
 * @param sp SearchParameters
 * @param q Query
 */
public void fromQuery(SearchParameters sp, Query q)
{
    ParameterCheck.mandatoryString("query", q.getQuery());
    String lang = q.getLanguage()==null?AFTS:q.getLanguage();

    switch (lang.toLowerCase())
    {
        case AFTS:
            sp.setLanguage(LANGUAGE_FTS_ALFRESCO);
            break;
        case LUCENE:
            sp.setLanguage(LANGUAGE_LUCENE);
            break;
        case CMIS:
            sp.setLanguage(LANGUAGE_CMIS_ALFRESCO);
            break;
        default:
            throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                        new Object[] { ": language allowed values: afts,lucene,cmis" });
    }
    sp.setQuery(q.getQuery());
    sp.setSearchTerm(q.getUserQuery());
}
 
Example 5
Source File: ResetPasswordServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void performResetPassword(DelegateExecution execution)
{
    // This method chooses to take a rather indirect route to access the password value.
    // This is for security reasons. We do not want to store the password in the Activiti DB.

    // We can get the username from the execution (process scope).
    final String userName = (String) execution.getVariable(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI);

    // But we cannot get the password from the execution as we have intentionally not stored the password there.
    // Instead we recover the password from the specific task in which it was set.
    List<Task> activitiTasks = activitiTaskService.createTaskQuery().taskDefinitionKey(WorkflowModelResetPassword.TASK_RESET_PASSWORD)
                .processInstanceId(execution.getProcessInstanceId()).list();
    if (activitiTasks.size() != 1)
    {
        throw new ResetPasswordWorkflowException("Unexpected count of task instances: " + activitiTasks.size());
    }
    Task activitiTask = activitiTasks.get(0);
    String activitiTaskId = activitiTask.getId();
    final String password = (String) activitiTaskService.getVariable(activitiTaskId, WorkflowModelResetPassword.WF_PROP_PASSWORD_ACTIVITI);

    if (LOGGER.isDebugEnabled())
    {
        LOGGER.debug("Retrieved new password from task " + activitiTaskId);
    }

    ParameterCheck.mandatoryString(WorkflowModelResetPassword.WF_PROP_USERNAME_ACTIVITI, userName);
    ParameterCheck.mandatoryString(WorkflowModelResetPassword.WF_PROP_PASSWORD_ACTIVITI, password);

    if (LOGGER.isDebugEnabled())
    {
        LOGGER.debug("Changing password for " + userName);
        // Don't LOG the password. :)
    }

    this.authenticationService.setAuthentication(userName, password.toCharArray());
}
 
Example 6
Source File: VirtualProtocol.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Reference newReference(Encoding encoding, Resource templateResource, String templatePath,
            Resource actualNodeResource, List<Parameter> extraParameters)
{
    ParameterCheck.mandatoryString("templatePath", templatePath);
    ArrayList<Parameter> parameters = new ArrayList<Parameter>(3);
    parameters.add(new StringParameter(templatePath));
    parameters.add(new ResourceParameter(actualNodeResource));
    parameters.addAll(extraParameters);
    return new Reference(encoding,
                         this,
                         templateResource,
                         parameters);
}
 
Example 7
Source File: SiteAwareFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 *
 * {@inheritDoc}
 */
@Override
public boolean delete(final String contentUrl)
{
    ParameterCheck.mandatoryString("contentUrl", contentUrl);

    final String effectiveContentUrl = this.checkAndAdjustInboundContentUrl(contentUrl, false);

    final boolean result = super.delete(effectiveContentUrl);
    return result;
}
 
Example 8
Source File: VirtualProtocol.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param templateNodeRef {@link NodeRef} of the template content holding
 *            repository node
 * @param templatePath
 * @param actualNodeRef
 * @return a new virtual protocol {@link Reference} with the given virtual
 *         protocol reference elements
 */
public Reference newReference(NodeRef templateNodeRef, String templatePath, NodeRef actualNodeRef)
{
    ParameterCheck.mandatoryString("templatePath", templatePath);
    return this.newReference(new RepositoryResource(new RepositoryNodeRef(templateNodeRef)),
                             templatePath,
                             actualNodeRef,
                             Collections.<Parameter> emptyList());
}
 
Example 9
Source File: CompositePasswordEncoder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *  Encode a password using the specified encoderKey
 * @param encoderKey the encoder to use
 * @param rawPassword  mandatory password
 * @param salt optional salt
 * @return the encoded password
 */
protected String encode(String encoderKey, String rawPassword, Object salt)
{
   ParameterCheck.mandatoryString("rawPassword", rawPassword);
   ParameterCheck.mandatoryString("encoderKey", encoderKey);
   Object encoder = encoders.get(encoderKey);
   if (encoder == null) throw new AlfrescoRuntimeException("Invalid encoder specified: "+encoderKey);
   if (encoder instanceof net.sf.acegisecurity.providers.encoding.PasswordEncoder)
   {
       net.sf.acegisecurity.providers.encoding.PasswordEncoder pEncoder = (net.sf.acegisecurity.providers.encoding.PasswordEncoder) encoder;
       if (MD4_KEY.equals(encoderKey))
       {
           //In the past MD4 password encoding didn't use a SALT
           salt = null;
       }
       if (logger.isDebugEnabled()) {
           logger.debug("Encoding using acegis PasswordEncoder: "+encoderKey);
       }
       return pEncoder.encodePassword(rawPassword, salt);
   }
   if (encoder instanceof org.springframework.security.crypto.password.PasswordEncoder)
   {
       org.springframework.security.crypto.password.PasswordEncoder passEncoder = (org.springframework.security.crypto.password.PasswordEncoder) encoder;
       if (logger.isDebugEnabled()) {
           logger.debug("Encoding using spring PasswordEncoder: "+encoderKey);
       }
       return passEncoder.encode(rawPassword);
   }

   throw new AlfrescoRuntimeException("Unsupported encoder specified: "+encoderKey);
}
 
Example 10
Source File: SiteAwareFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean exists(final String contentUrl)
{
    ParameterCheck.mandatoryString("contentUrl", contentUrl);

    final Pair<String, String> urlParts = this.getContentUrlParts(contentUrl);
    final String protocol = urlParts.getFirst();
    final String effectiveContentUrl = this.checkAndAdjustInboundContentUrl(contentUrl,
            EqualsHelper.nullSafeEquals(StoreConstants.WILDCARD_PROTOCOL, protocol));

    final boolean result = super.exists(effectiveContentUrl);
    return result;
}
 
Example 11
Source File: ResetPasswordServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ClientApp getClientAppConfig(String clientName)
{
    ParameterCheck.mandatoryString("clientName", clientName);

    ClientApp clientApp = clientAppConfig.getClient(clientName);
    if (clientApp == null)
    {
        throw new ClientAppNotFoundException("Client was not found [" + clientName + "]");
    }
    return clientApp;
}
 
Example 12
Source File: SiteAwareFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ContentReader getReader(final String contentUrl)
{
    ParameterCheck.mandatoryString("contentUrl", contentUrl);

    final Pair<String, String> urlParts = this.getContentUrlParts(contentUrl);
    final String protocol = urlParts.getFirst();
    final String effectiveContentUrl = this.checkAndAdjustInboundContentUrl(contentUrl,
            EqualsHelper.nullSafeEquals(StoreConstants.WILDCARD_PROTOCOL, protocol));

    final ContentReader reader = super.getReader(effectiveContentUrl);
    return reader;
}
 
Example 13
Source File: CustomModelServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns compiled custom model and whether the model is active or not as a {@code Pair} object
 *
 * @param modelName the name of the custom model to retrieve
 * @return the {@code Pair<CompiledModel, Boolean>} (or null, if it doesn't exist)
 */
protected Pair<CompiledModel, Boolean> getCustomCompiledModel(String modelName)
{
    ParameterCheck.mandatoryString("modelName", modelName);

    final NodeRef modelNodeRef = getModelNodeRef(modelName);

    if (modelNodeRef == null || !nodeService.exists(modelNodeRef))
    {
        return null;
    }

    M2Model model = null;
    final boolean isActive = Boolean.TRUE.equals(nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE));
    if (isActive)
    {
        QName modelQName = (QName) nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_NAME);
        if (modelQName == null)
        {
            return null;
        }
        try
        {
            CompiledModel compiledModel = dictionaryDAO.getCompiledModel(modelQName);
            model = compiledModel.getM2Model();
        }
        catch (Exception e)
        {
            throw new CustomModelException(MSG_RETRIEVE_MODEL, new Object[] { modelName }, e);
        }
    }
    else
    {
        model = getM2Model(modelNodeRef);
    }

    Pair<CompiledModel, Boolean> result = (model == null) ? null : new Pair<>(compileModel(model), isActive);

    return result;
}
 
Example 14
Source File: CustomModelServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ModelDefinition getCustomModelByUri(String namespaceUri)
{
    ParameterCheck.mandatoryString("namespaceUri", namespaceUri);
    CompiledModel compiledModel = getModelByUri(namespaceUri);

    if (compiledModel != null)
    {
        return compiledModel.getModelDefinition();
    }
    return null;
}
 
Example 15
Source File: CustomModelServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public CustomModelDefinition getCustomModel(String modelName)
{
    ParameterCheck.mandatoryString("modelName", modelName);

    Pair<CompiledModel, Boolean> compiledModelPair = getCustomCompiledModel(modelName);
    CustomModelDefinition result = (compiledModelPair == null) ? null : new CustomModelDefinitionImpl(
                compiledModelPair.getFirst(), compiledModelPair.getSecond(), dictionaryService);

    return result;
}
 
Example 16
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 ** SearchParameters from List<FilterQuery>
 * @param sp
 * @param filterQueries
 */
public void fromFilterQuery(SearchParameters sp, List<FilterQuery> filterQueries)
{
    if (filterQueries != null && !filterQueries.isEmpty())
    {
        if (LANGUAGE_CMIS_ALFRESCO.equals(sp.getLanguage()))
        {
            throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                        new Object[] { ": filterQueries {} not allowed with cmis language" });
        }
        for (FilterQuery fq:filterQueries)
        {
            String query = null;

            if (fq.getQuery() != null && !fq.getQuery().isEmpty())
            {
                query = fq.getQuery().trim();
            }

            if (fq.getQueries() != null && !fq.getQueries().isEmpty() && query == null)
            {
                query = String.join(" OR ", fq.getQueries());
            }

            ParameterCheck.mandatoryString("filterQueries query", query);

            if (fq.getTags() == null || fq.getTags().isEmpty() || query.contains("afts tag"))
            {
                //If its already got tags then just let it through
                sp.addFilterQuery(query);
            }
            else
            {
                String tags = "tag="+String.join(",", fq.getTags());
                Matcher matcher = LuceneQueryLanguageSPI.AFTS_QUERY.matcher(query);
                if (matcher.find())
                {
                    query = "{!afts "+tags+" "+matcher.group(1).trim()+"}"+matcher.group(2);
                }
                else
                {
                    query = "{!afts "+tags+" }"+query;
                }
                sp.addFilterQuery(query);
            }
        }
    }
}
 
Example 17
Source File: NameValidator.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean validates(String fieldName)
{
    ParameterCheck.mandatoryString("fieldName", fieldName);
    return (fieldName.equals("name"));
}
 
Example 18
Source File: TypeVirtualizationMethod.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setQnameFilters(String filters)
{
    ParameterCheck.mandatoryString("filters",
                                   filters);
    this.filters = filters;
}
 
Example 19
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void buildPivotKeys(List<String> pivotKeys, Pivot aPivot, List<StatsRequestParameters> stats, FacetFields facetFields,
            List<RangeParameters> ranges, SearchRequestContext searchRequestContext)
{
    if (aPivot == null) return;
    String pivotKey = null;
    ParameterCheck.mandatoryString("pivot key", aPivot.getKey());

    if (facetFields.getFacets() != null && !facetFields.getFacets().isEmpty())
    {
        Optional<FacetField> found = facetFields.getFacets().stream()
                    .filter(queryable -> aPivot.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();

        if (found.isPresent())
        {
            pivotKey = aPivot.getKey();
            if (searchRequestContext.getPivotKeys().containsValue(pivotKey))
            {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                            new Object[] { ": Duplicate pivot parameter " + aPivot.getKey() + "" });
            }

            pivotKeys.add(found.get().getField());
            facetFields.getFacets().remove(found.get());
            searchRequestContext.getPivotKeys().put(found.get().getField(), pivotKey);
        }
    }

    if (pivotKey == null && ((aPivot.getPivots() == null) || aPivot.getPivots().isEmpty()))
    {
        //It is the last one so it can reference stats or range
        if (stats != null && !stats.isEmpty())
        {
            Optional<StatsRequestParameters> foundStat =  stats.stream().filter(stas -> aPivot.getKey().equals(stas.getLabel()!=null?stas.getLabel():stas.getField())).findFirst();
            if (foundStat.isPresent())
            {
                pivotKey = aPivot.getKey();
                if (pivotKeys.isEmpty())
                {
                    throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                                new Object[] { ": Stats key " + pivotKey + " cannot be used here" });
                }
                pivotKeys.add(pivotKey);
                searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
            }
        }

        if (ranges != null && !ranges.isEmpty())
        {
            for (RangeParameters aRange:ranges)
            {
                if (aPivot.getKey().equals(aRange.getLabel()))
                {
                    pivotKey = aPivot.getKey();
                    if (pivotKeys.isEmpty())
                    {
                        throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                                    new Object[] { ": Range key " + pivotKey + " cannot be used here" });
                    }
                    pivotKeys.add(pivotKey);
                    searchRequestContext.getPivotKeys().put(pivotKey, pivotKey);
                }
            }
        }
    }

    if (pivotKey == null)
    {
        String invalidMessage = searchRequestContext.getPivotKeys().values().contains(aPivot.getKey())
                    ? " cannot be used more than once.":" does not reference a facet Field, range or stats.";
        throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                    new Object[] { ": Pivot parameter " + aPivot.getKey() + invalidMessage });
    }

    if (aPivot.getPivots() != null && !aPivot.getPivots().isEmpty() && aPivot.getPivots().size()>1)
    {
        throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                    new Object[] { ": Currently only 1 nested pivot is supported, you have "+aPivot.getPivots().size()});
    }

    aPivot.getPivots().forEach(subPivot ->
    {
        buildPivotKeys(pivotKeys, subPivot, stats, facetFields, ranges, searchRequestContext);
    });

}
 
Example 20
Source File: AbstractContentAccessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Allow derived implementations to set the Content URL.  This allows for implementations
 * where the URL is not known when the accessor is first constructed.
 * 
 * @param contentUrl            the new content URL
 */
protected void setContentUrl(String contentUrl)
{
    ParameterCheck.mandatoryString("contentUrl", contentUrl);
    this.contentUrl = contentUrl;
}