LDAP callback functionality - aem

Masters,
I'm trying to implement LDAP callback functionality by referring to this article under "CALLBACKS"
I've configured LDAP without issue. My requirement is assign ldap user to CRX group depending on attribute in DS server. Now As per my understanding, when LDAP user will attempt login first time then CQ will automatically call my class which implements Callback interface. Please correct me if I am wrong.
So, I decided to create bundle which implements Callback interface. With my little knowledge I have done this so far -
i) In CRXDE lite, I added one bundle under geometrixx project and attached is the simple code but during building bundle I got error saying that Callback cannot be resolved to a type.
import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.api.security.user.Group;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.jcr.SimpleCredentials;
public class SyncUser implements com.day.crx.security.ldap.sync.Callback{
#Override
public void onUserSync(User userToBeSynched, Map<String, Value[]> attributes,
ValueFactory valueFactory) throws RepositoryException {
Iterator iter = attributes.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry mEntry = (Map.Entry) iter.next();
javax.jcr.Value val = (javax.jcr.Value)mEntry.getValue();
// Error** [Ljavax.jcr.Value; cannot be cast to javax.jcr.Value
System.out.println(mEntry.getKey() + " : " + val.getString());
}
}
#Override
public void onGroupSync(Group group,
Map<String, Value[]> attributes,
ValueFactory vf) throws RepositoryException{
System.out.println("Hello onGroupSync");//do my stuff
}
}
I could not find any documentation about this com.day.crx.security.ldap.sync.Callback interface. Kindly guide me. Appreciate your help

Here is at least some documentation for com.day.crx.security.ldap.sync.Callback: https://docs.adobe.com/docs/en/cq/5-6-1/core/administering/ldap_authentication.html#Callbacks
The doc you referenced says this:
The callback interface is located in the crx-auth-ldap module and has
the following methods that need to be implemented:
You need at least the following dependencies (jar files) to create and
build a callback class:
jcr-<version>.jar
crx-auth-<version>.jar
Both are bundled with the CRX Explorer Web Application and can be
extracted from the war file.
After you compiled and packaged the callback class you need to make it
available to CRX. The easiest way is to place the the custom callback
implementation along with the CRX webapp at
crx-quickstart/server/runtime/0/_crx/WEB-INF/[lib|classes].

Related

How to ignore package when building flutter project for web?

I have a project which uses flutter_libserialport library on macOS.
I am modifying it to work on web however this library does not work on web.
I am building a web implementation using navigator.serial in javascript which works fine.
However when I attempt to build the project for web I get the following error
/opt/homebrew/Caskroom/flutter/2.2.3/flutter/.pub-cache/hosted/pub.dartlang.org/libserialport-0.2.0+3/lib/src/config.dart:25:8: Error: Not found: 'dart:ffi'
import 'dart:ffi' as ffi;
This makes sense since FFI is not available on web.
But I don't even need the libserialport library on web any way.
How can I get flutter to ignore it?
I tried this however it doesn't contain information on how to exclude a package.
It also does not contain information on how to ignore it specifically for web. It seems to just ignore it in general.
Maybe you should guard your usages of libserialport with the kIsWeb predicate like following:
if(!kIsWeb){
// libserialport code execution here
}
I searched a lot as well and didn't find a way you can do that, I think this should be handled by the package itself not the package's users like in path_provider for instance.
As a workaround I have created a dummy libserialport's SerialPort class for web only as follows:
dummy_serialport.dart:
class SerialPort {
final String name;
static List<String> availablePorts = ['dummy'];
static SerialPortError? lastError;
SerialPort(this.name);
bool openReadWrite() {
return false;
}
}
class SerialPortError {}
// add more properties and functions as needed
main.dart:
import 'package:libserialport/libserialport.dart'
if (dart.library.html) './dummy_serialport.dart'
if (dart.library.io) 'package:libserialport/libserialport.dart';
....
if (!kIsWeb) {
final name = SerialPort.availablePorts.first;
final port = SerialPort(name);
if (!port.openReadWrite()) {
print(SerialPort.lastError);
exit(-1);
}
}
....
....
It's bad, I know :( but it works! maybe you can contact the package author to get more insight and if opening a PR where the interfaces are separated from the FFI implementation so that importing the classes wouldn't break web or something.

How to implement the Xtext-XMI cross reference for LSP based editor in Theia?

I am working on creating a LSP based editor in Theia for one of our DSL, from this DSL we need to cross reference model defined in separate XMI file on the basis of FullQualifiedName.
I am able to implement this for eclipse plugin but unable to implement it for theia based editor. If there is any existing sample that is implementing this functionality in thiea then it would be great.
Solution -
Suppose we have defined a model in EMF which we can edit either using XMI based editor or text based Xtext editor .In a LSP based setup to cross refer the models defined in XMI file from Xtext based editor follow below steps -
1.Create a new project for defining the linkage.
2.Create a Runtime Module class to configure the runtime dependency
package io.typefox.xtextxmi.xtree.treeintegration
import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider
class TreeRuntimeModule extends AbstractGenericResourceRuntimeModule {
override protected getFileExtensions() {
'tree'
}
override protected getLanguageName() {
'io.typefox.xtextxmi.tree.Tree'
}
override bindIQualifiedNameProvider() {
DefaultDeclarativeQualifiedNameProvider
}
// bind additional services here
}
3.Create a Standalone Setup for activation
import com.google.inject.Inject
import org.eclipse.xtext.resource.FileExtensionProvider
import org.eclipse.xtext.ISetup
import org.eclipse.xtext.resource.IResourceServiceProvider
import com.google.inject.Guice
import io.typefox.xtextxmi.tree.TreePackage
import org.eclipse.emf.ecore.resource.Resource
import com.google.inject.Injector
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
class TreeStandaloneSetup implements ISetup {
#Inject
private FileExtensionProvider fileExtensionProvider;
#Inject
private IResourceServiceProvider resourceServiceProvider;
#Inject
private IResourceServiceProvider.Registry registry;
override createInjectorAndDoEMFRegistration() {
val injector = Guice.createInjector(new TreeRuntimeModule)
injector.injectMembers(this);
for (String fileExt : fileExtensionProvider.getFileExtensions())
registry.getExtensionToFactoryMap().put(fileExt, resourceServiceProvider)
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("tree", new XMIResourceFactoryImpl)
// the following implicitly registers the EPackage to the registry
TreePackage.eINSTANCE.eClass()
return injector
}
}
3.Define a ISetup file to register the TreeStandaloneSetup , folder structure should look like this:
src->META-INF->services->org.eclipse.xtext.ISetup
Add a entry for full qualified name of Standalone setup class in the ISetup file-
io.typefox.xtextxmi.xtree.treeintegration.TreeStandaloneSetup
4.Make sure to add this project to the classpath of ".ide" project , if it is maven/gradle based then simply add it to pom.xml/build.gradle of .ide project.
Note - I have used the sample given in Link & extended it for Eclipse Theia based LSP editor.

Setting a eclipse plug-in to singleton when creating a plug-in project via IPluginContentWizard interface

I'm developing a wizard that implements the org.eclipse.pde.ui.IPluginContentWizard interface. Thus it gets added as plug-in project template in the end of the plug-in project wizard. All files will be created just fine, but there is one error in the project. The plug-in is not declared to be a singleton which it must be when extending extension points.
How do I do that within the wizard? I figured it needs to be done in performFinish(IProject project, IPluginModelBase model, IProgressMonitor monitor) but neither the project nor the model gives me a possibility to do so.
Edit: For future readers: My mistake was, that I didn't add the extension via the API but rather via generating the plugin.xml "by hand". This caused no mechanism in the background to do their job and thus the singleton directive wasn't set.
This way will be too long, let's use more PDE API:
First, define the template section
import org.eclipse.pde.ui.templates.OptionTemplateSection;
public class YourTemplateSection extends OptionTemplateSection {
//implement abstract methods according your needs
#Override
protected void updateModel(IProgressMonitor monitor) throws CoreException {
IPluginBase plugin = model.getPluginBase();
//do what is needed
plugin.add(extension);//here the "singleton" directive will be set
}
}
then use the section with wizard
import org.eclipse.pde.ui.templates.ITemplateSection;
import org.eclipse.pde.ui.templates.NewPluginTemplateWizard;
public class YourContentWizard extends NewPluginTemplateWizard {
#Override
public ITemplateSection[] createTemplateSections() {
return new ITemplateSection[] { new YourTemplateSection() };
}
}
In case one does the same rookie mistake then me, I wanted to post my solution I came up after revisiting the project later:
Don't create the plugin.xml manually, use the PDE API of the plugin model to add extensions.
In the org.eclipse.pde.ui.IPluginContentWizard implementions's performFinish(...) method do this:
try {
IPluginExtension extension = model.getExtensions().getModel().getFactory().createExtension();
extension.setPoint("org.eclipse.elk.core.layoutProviders");
IPluginElement provider = model.getPluginFactory().createElement(extension);
provider.setName("provider");
provider.setAttribute("class", id + "." + algorithmName + "MetadataProvider");
extension.add(provider);
model.getExtensions().add(extension);
} catch (CoreException e) {
e.printStackTrace();
}

Webdriver can login in Chrome, not in firefox: 'Unable to find owning document' error

I have 2 classes belonging to the same package in a java testNG project and I have declared 'webdriver driver' public static in class A. In that class, chrome launched, url opened, username and password were entered and login button clicked. Worked fine using #BeforeClass annotation.
I copied the same code into a class B and changed browser instance to firefox whilst still declaring 'webdriver driver as public static. Firefox Launched, URL opened, username and password were entered but login button did not click or submit. Test failed with the error:
org.openqa.selenium.JavascriptException: Error: Unable to find owning document.
I have never come across this error and have no idea what 'owning document' is being referred to.I am suspecting it has something to do with the access level for either or both classes. Below is an extract from the 2 classes. Am I missing something?
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheChrome {
public static WebDriver driver;
#BeforeClass(alwaysRun = true)
public void launchBrowser() {
driver = new ChromeDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
#Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
*
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TheFirefox {
public static WebDriver driver;
#BeforeClass(alwaysRun = true)
public void launchBrowser() throws InterruptedException {
driver = new FirefoxDriver();
driver.get("http://www.example.com");
driver.manage().window().maximize();
Thread.sleep(3000);
}
#Test
public void verifyLogin() throws InterruptedException {
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
Thread.sleep(3000);
driver.findElement(By.id("loginButton")).click();
edit: See this very relevant question and answer
If you edit the post to include relevant html, this would be easier to help with.
Try with cssSelector:
Inspect the login button. Within the inspector, right click the element and copy the CSS Selector.
driver.findElement(By.cssSelector("copypasta")).click();
Try to locate by xpath using several different methods listed in this useful cheat sheet.
For example, if the inner html text for your button is 'Login':
driver.findElement(By.xpath("//button[contains(text(), 'Login']")).click();
There are many different ways to do this, so looking at your html will help people help you, I think.
This is an issue caused by the Firefox version in use, 49.0.2. It's a weird case and unclear why login functionality is being imparted by the browser version in use;however, resolving the issue requires a downgrade to version 46.0. This fixed the problem.

Where do you find the JDBCProvider Interface?

As part of my ongoing JDBC/Oracle saga, I solicited the help of one of our Java/JDBC experts and after receiving some more input via my last question "For JDBC in XPages, how does the server know the connection information?" we imbarked on creating a plugin for my ojdbc14.jar file. We got the plugin created and tried to complile it. It complained that it could not find the JDBCProvider Interface. My question is where do I find this? Is this part of the Extension Library files on the Server or is this something completely different?
As always, any help will be greatly appreciated.
Thanks,
MJ
You'll want to pick com.ibm.commons.Extension in the Extension Point dialog, and then set the type as com.ibm.commons.jdbcprovider. Set the class to your JDBC driver provider class (named com.ZetaOne.JDBC.drivers.DB2.DB2DriverProvider for example) which i've provided sample code for below that looks like this (customized to your particular driver, etc)
package com.ZetaOne.JDBC.drivers.DB2;
import java.sql.Driver;
import java.sql.SQLException;
import com.ibm.commons.jdbc.drivers.IJDBCDriverAlias;
import com.ibm.commons.jdbc.drivers.JDBCProvider;
public class DB2DriverProvider implements JDBCProvider {
public DB2DriverProvider() {
{
public Driver loadDriver(String className) throws SQLException {
if(classNmae.equals(com.ibm.db2.jcc.DB2Driver.class.getName())) {
return new com.ibm.db2.jcc.DB2Driver();
}
return null;
}
}
Assuming you've done everything else needed for the plugin, you should be able to export / create your update site and install the driver.
BTW, you'll be able to read how to setup & deploy and use the JDBC package in ExtLibX in our upcoming book "XPages Extension Library: A Step by Step Guide to the Next Generation of XPage Controls" - available on amazon pre-order at http://www.amazon.com/XPages-Extension-Library-Step---Step/dp/0132901811
Hope this helps.