cancel
Showing results for 
Search instead for 
Did you mean: 

AuthenticationCredentialsNotFoundException error for search

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi,

I am using Alfresco 3.2r with Tomcat 6 with JDK 1.6.

I have written below code to get children of companyhome as:

StoreRef storeRef5 = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet rs = serviceRegistry.getSearchService().query(storeRef5, SearchService.LANGUAGE_XPATH, "/app:company_home");
       NodeRef companyHomeNodeRef = null;
       try
       {
           if (rs.length() == 0)
           {
               throw new AlfrescoRuntimeException("Didn't find Company Home");
           }
           companyHomeNodeRef = rs.getNodeRef(0);
       }catch (Exception e) {
         logger.error("Error while getting company home "+e.getMessage());
      }
       List<ChildAssociationRef> children = serviceRegistry.getNodeService().getChildAssocs(companyHomeNodeRef);
        for (ChildAssociationRef childAssoc : children) {
            NodeRef childNodeRef = childAssoc.getChildRef();
           logger.debug("childNodeRef "+" "+childNodeRef.getId()+childNodeRef.getStoreRef());
        }

While i am trying to invoke it, i am getting below error :

net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceedWithAudit(AuditMethodInterceptor.java:238)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:205)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:153)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy27.query(Unknown Source)
   at com.xxxx.alfresco.km.constraints.CommunitySearchConstraint.getAllowedValues(CommunitySearchConstraint.java:182)
   at org.alfresco.cmis.dictionary.CMISBasePropertyDefinition.<init>(CMISBasePropertyDefinition.java:108)
   at org.alfresco.cmis.dictionary.CMISAbstractTypeDefinition.createProperty(CMISAbstractTypeDefinition.java:126)
   at org.alfresco.cmis.dictionary.CMISAbstractTypeDefinition.createProperties(CMISAbstractTypeDefinition.java:104)…..


Line no 182 says:

ResultSet rs = serviceRegistry.getSearchService().query(storeRef5, SearchService.LANGUAGE_XPATH, "/app:company_home");

I can assume that it is related to service dependency injection but not getting how to resolve it.

Can anybody tell me how to achieve this: maybe by making my class as managed bean & injecting searchservice in faces-config-beans.xml??? :?

Is there any generic way that i can get any service without any error outside of alfresco i.e. my custom code?

Any idea?

Is there any change in way to get services in 3.2+?
8 REPLIES 8

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi,

I just came across this wiki article:

http://wiki.alfresco.com/wiki/Java_Foundation_API

It says :

Access to Java Foundation API
The Java Foundation API is in fact a set of interfaces; each interface represents a function of the repository. A Spring Framework Bean is provided as the implementation for each interface.

The list of available public services (that is, Spring beans) can be found in:

the configuration file /projects/repository/config/alfresco/public-services-context.xml
the service interface org.alfresco.service.ServiceRegistry
There are three approaches to accessing the interfaces in your own code:

Use standard Spring dependency injection (recommended, if your client code is also Spring based)
Manual access via the Spring getBean() method
Indirectly via Alfresco's ServiceRegistry
Spring provides excellent documentation on how to bind Beans together, so that will not be duplicated here.

I have tried all approaches  but error remains same.:shock:

thestorm
Champ in-the-making
Champ in-the-making
the custom constraint works just with versions till labs 3.0 after that they changed the security context so thats not working anymore Smiley Sad

i hope the developers will do that option one day, since its very usefull to add customers as propertie to your documents and put them into workflows Smiley Happy

mrogers
Star Contributor
Star Contributor
You should have a secure context, how are you running your code without a secure context?

There's three approaches you can use.
a) Use the AuthenticationUtil class to establish a secure context.
b) Use the AuthenticationUtil class to run as the system user.
c) Bypass the security check by using the internal services (the one with the lower case name).

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi,

i got list of all categories coming up in content properties page. Smiley Happy


Please refer to this post of mine:

http://forums.alfresco.com/en/viewtopic.php?f=9&t=20589&p=84639#p84639

bwagner
Champ in-the-making
Champ in-the-making
How did you solve the problem with the secure context?

robain
Champ in-the-making
Champ in-the-making
I am having similar problem when trying to upgrade from 3.1 to 3.3. getting the following error on startup for one of the constraint that uses lucene search to get the list of allowed values without the security context. It fails on the line highlighted below  in the code

Any help is much appreciated.


public class LuceneSearchBasedListConstraint extends SearchBasedDependencyListConstraint{

    private static final long serialVersionUID = 1L;
   
   protected static Logger logger = Logger.getLogger(LuceneSearchBasedListConstraint.class);
   protected String query;
   protected String strStoreRef =
      StoreRef.PROTOCOL_WORKSPACE + StoreRef.URI_FILLER +  "SpacesStore";

    public LuceneSearchBasedListConstraint(){}
   
   @Override
   protected List<String> getSearchResult(){
      if(logger.isDebugEnabled())
         logger.debug("Original Query " + query);

      String siteQuery = getSites(query);

      //this is where the query from the alfresco content model constraints comes in.
      StoreRef storeRef = new StoreRef(strStoreRef);
      [size=150]ResultSet resultSet = getServiceRegistry().getSearchService().query(storeRef, SearchService.LANGUAGE_LUCENE, siteQuery);[/size]
      NodeService nodeSvc = getServiceRegistry().getNodeService();

      Collection<String> allowedValues = new TreeSet<String>();
      
      for (ResultSetRow row : resultSet)
         allowedValues.add((String)nodeSvc.getProperty(row.getNodeRef(), ContentModel.PROP_NAME));
      
      return  new ArrayList<String>(allowedValues);
   }

romschn
Star Collaborator
Star Collaborator
Before you perform the search, your user must be validated/authenticated against alfresco repository to avoid the error you are getting.

Hope this helps.

Thanks,

mitpatoliya
Star Collaborator
Star Collaborator

All code which do critical operations against repository requires to run with secure context and within one single transaction.

You can achieve this by putting code under runas block.

AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {

                public Void doWork(){

                 //Put you logic here

                    }

                       return null;

                }

            }, AuthenticationUtil.getSystemUserName());

Hope this helps to all other users.