use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class EmailServiceImpl method getUsername.
/**
* Authenticate in Alfresco repository by sender's e-mail address.
*
* @param from Sender's email address
* @return User name or null if the user does not exist.
* @throws EmailMessageException Exception will be thrown if authentication is failed.
*/
private String getUsername(String from) {
String userName = null;
if (from == null || from.length() == 0) {
return null;
}
if (logger.isDebugEnabled()) {
logger.debug("getUsername from: " + from);
}
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
String query = "TYPE:cm\\:person AND =@cm\\:email:\"" + from + "\"";
ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_FTS_ALFRESCO, query);
try {
if (resultSet == null || resultSet.length() == 0) {
return null;
}
if (resultSet.length() > 1) {
if (logger.isWarnEnabled()) {
logger.warn("found more as one result for email '" + from + "'. The first will be used");
}
}
NodeRef userNode = resultSet.getNodeRef(0);
if (nodeService.exists(userNode)) {
userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(userNode, ContentModel.PROP_USERNAME));
if (logger.isDebugEnabled()) {
logger.debug("found username: " + userName);
}
} else {
// The Lucene index returned a dead result
throw new EmailMessageException(ERR_UNKNOWN_SOURCE_ADDRESS, from);
}
} finally {
if (resultSet != null) {
resultSet.close();
}
}
return userName;
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ACLEntryAfterInvocationProvider method decide.
@SuppressWarnings("rawtypes")
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject) throws AccessDeniedException {
if (log.isDebugEnabled() && object instanceof MethodInvocation) {
MethodInvocation mi = (MethodInvocation) object;
log.debug("Method: " + mi.getMethod().toString());
}
try {
if (AuthenticationUtil.isRunAsUserTheSystemUser()) {
if (log.isDebugEnabled()) {
log.debug("Allowing system user access");
}
return returnedObject;
} else if (returnedObject == null) {
if (log.isDebugEnabled()) {
log.debug("Allowing null object access");
}
return null;
} else if (PermissionCheckedValue.class.isAssignableFrom(returnedObject.getClass())) {
// The security provider was not already present
return decide(authentication, object, config, (PermissionCheckedValue) returnedObject);
} else if (PermissionCheckValue.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (PermissionCheckValue) returnedObject);
} else if (StoreRef.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, nodeService.getRootNode((StoreRef) returnedObject)).getStoreRef();
} else if (NodeRef.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (NodeRef) returnedObject);
} else if (Pair.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (Pair) returnedObject);
} else if (ChildAssociationRef.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (ChildAssociationRef) returnedObject);
} else if (SolrJSONResultSet.class.isAssignableFrom(returnedObject.getClass()) && (!anyDenyDenies || (!postProcessDenies && ((SolrJSONResultSet) returnedObject).getProcessedDenies()))) {
return returnedObject;
} else if (CMISResultSet.class.isAssignableFrom(returnedObject.getClass())) {
return returnedObject;
} else if (PagingLuceneResultSet.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (PagingLuceneResultSet) returnedObject);
} else if (ResultSet.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (ResultSet) returnedObject);
} else if (QueryEngineResults.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (QueryEngineResults) returnedObject);
} else if (Collection.class.isAssignableFrom(returnedObject.getClass())) {
return decide(authentication, object, config, (Collection) returnedObject);
} else if (returnedObject.getClass().isArray()) {
return decide(authentication, object, config, (Object[]) returnedObject);
} else {
if (log.isDebugEnabled()) {
log.debug("Uncontrolled object - access allowed for " + object.getClass().getName());
}
return returnedObject;
}
} catch (AccessDeniedException ade) {
if (log.isDebugEnabled()) {
log.debug("Access denied");
ade.printStackTrace();
}
throw ade;
} catch (RuntimeException re) {
if (log.isDebugEnabled()) {
log.debug("Access denied by runtime exception");
re.printStackTrace();
}
throw re;
}
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class VirtualQueryImpl method perform.
@Override
public PagingResults<Reference> perform(ActualEnvironment environment, VirtualQueryConstraint constraint, PagingRequest pagingRequest, Reference parentReference) throws VirtualizationException {
VirtualQueryConstraint theConstraint = constraint;
if (pagingRequest != null) {
theConstraint = new PagingRequestConstraint(theConstraint, pagingRequest);
}
SearchParameters searchParameters = theConstraint.apply(environment, this);
ResultSet result = environment.query(searchParameters);
if (logger.isDebugEnabled()) {
logger.debug("Constrained query " + searchParameters + " resulted in " + result.length() + " rows.");
}
return asPagingResults(environment, pagingRequest, result, parentReference);
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ReadPermissionTest method testNodeOwner.
public void testNodeOwner() {
SearchParameters sp;
ResultSet results;
buildOwnedNodes("1001", 0);
runAs(AuthenticationUtil.getAdminUserName());
runAs("1001");
sp = new SearchParameters();
sp.addStore(rootNodeRef.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("PATH:\"//*\"");
sp.setMaxItems(Integer.MAX_VALUE);
sp.setMaxPermissionChecks(Integer.MAX_VALUE);
sp.setMaxPermissionCheckTimeMillis(Integer.MAX_VALUE);
results = serviceRegistry.getSearchService().query(sp);
int length = results.length();
results.close();
// folder + children
assertEquals(1001, length);
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class ReadPermissionTest method testNoRead.
public void testNoRead() {
SearchParameters sp;
ResultSet results;
build1000Nodes("1001", PermissionService.WRITE, true);
runAs("1001");
sp = new SearchParameters();
sp.addStore(rootNodeRef.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("TYPE:\"cm:content\"");
sp.setMaxItems(Integer.MAX_VALUE);
sp.setMaxPermissionChecks(Integer.MAX_VALUE);
sp.setMaxPermissionCheckTimeMillis(Integer.MAX_VALUE);
results = serviceRegistry.getSearchService().query(sp);
int length = results.length();
results.close();
assertEquals(0, length);
}
Aggregations