RE: Customizing the AutoLogin

thumbnail
saravanan muniraj, modified 6 Years ago. Junior Member Posts: 95 Join Date: 6/1/11 Recent Posts
Hi,I am working on the  customizing the autoLogin for DXP 7.1 here is the code snippet @Component(immediate = true, service = AutoLogin.class)
public class CagAutoLogin implements AutoLogin {    public String[] handleException(HttpServletRequest request, HttpServletResponse response, Exception e)
            throws AutoLoginException {
        return null;
    }
    public String[] login(
            HttpServletRequest request, HttpServletResponse response)
        throws AutoLoginException {        String[] credentials = null;
        long companyId = PortalUtil.getCompanyId(request);
        com.liferay.portal.kernel.model.User autoLoginUser = null;        try {
            autoLoginUser = _userLocalService.getUserByEmailAddress(companyId, "muniraj@liferay.com"); // later dynamic user id will be replaced
        }
        catch (Exception e) {
        }        if (autoLoginUser != null) {
            credentials = new String[3];            credentials[0] = String.valueOf(autoLoginUser.getUserId());
            credentials[1] = autoLoginUser.getPassword();
            credentials[2] = Boolean.toString(true);
        }        return credentials;
    }
    @Reference
    private UserLocalService _userLocalService;}------- Gradle Build----
dependencies {
   compileOnly [b]group[/b]: [b]'com.liferay.portal'[/b], [b]name[/b]: [b]'com.liferay.portal.kernel'[/b], [b]version[/b]: [b]'3.0.0'
[/b][b]   [/b]compileOnly [b]group[/b]: [b]"javax.portlet"[/b], [b]name[/b]: [b]"portlet-api"[/b], [b]version[/b]: [b]"3.0.0"
[/b][b]   [/b]compileOnly [b]group[/b]: [b]"javax.servlet"[/b], [b]name[/b]: [b]"javax.servlet-api"[/b], [b]version[/b]: [b]"3.1.0"
[/b][b]   [/b]compileOnly [b]group[/b]: [b]"org.osgi"[/b], [b]name[/b]: [b]"osgi.cmpn"[/b], [b]version[/b]: [b]"6.0.0"
[/b][b]   [/b]compileOnly [b]group[/b]: [b]"org.osgi"[/b], [b]name[/b]: [b]"osgi.core"[/b], [b]version[/b]: [b]"6.0.0"
[/b][b]   [/b]compileOnly [b]group[/b]: [b]"org.osgi"[/b], [b]name[/b]: [b]"org.osgi.service.component.annotations"[/b], [b]version[/b]: [b]"1.3.0"
[/b][b]
[/b][b]   [/b]compileOnly [b]group[/b]: [b]'com.sun.xml.ws'[/b], [b]name[/b]: [b]'jaxws-rt'[/b], [b]version[/b]: [b]'2.1.4'
[/b][b]
[/b]}
-------BND ----
[b]Include-Resource[/b]:\
[b]              @org.osgi.service.component.annotations-1.3.0.jar,\
[/b][b]              @jaxws-rt-2.1.4.jar,\
[/b][b]              @javax.servlet-api-3.1.0.jar,\
[/b][b]              @com.liferay.portal.kernel-3.0.0.jar,\
[/b][b]              @portlet-api-3.0.0.jar[/b]
-------Note : jaxws-rt-2.1.4.jar is include to call web service 
the jar is building fine , while deploying the following  error I am encountered:
2019-09-19 19:39:46.714 ERROR [Framework Event Dispatcher: Equinox Container: ff474c7b-08b2-4184-a815-02f27afbce14][org_eclipse_osgi:97] FrameworkEvent ERROR 
java.lang.ClassCastException: com.citizensfla.portal.autologin.CagAutoLogin cannot be cast to com.liferay.portal.kernel.security.auto.login.AutoLogin
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter$AutoLoginServiceTrackerCustomizer.addingService(AutoLoginFilter.java:288)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter$AutoLoginServiceTrackerCustomizer.addingService(AutoLoginFilter.java:273)
    at com.liferay.registry.internal.ServiceTrackerCustomizerAdapter.addingService(ServiceTrackerCustomizerAdapter.java:35)
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:943)
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
    at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:903)
    at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:891)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:804)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:228)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:906)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:892)
    at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:128)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:959)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:732)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:666)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:432)
    at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:665)
    at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:339)
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:381)
    at org.apache.felix.scr.impl.Activator.access$200(Activator.java:49)
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:263)
    at org.apache.felix.scr.impl.AbstractExtender.createExtension(AbstractExtender.java:196)
    at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:169)
    at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:49)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:488)
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1)
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:230)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:137)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:129)
    at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:191)
    at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
    at org.eclipse.osgi.container.Module.start(Module.java:467)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:468)
    at org.eclipse.osgi.container.ModuleContainer.start(ModuleContainer.java:777)
    at org.eclipse.osgi.container.ModuleContainer.applyDelta(ModuleContainer.java:768)
    at org.eclipse.osgi.container.ModuleContainer.resolveAndApply(ModuleContainer.java:538)
    at org.eclipse.osgi.container.ModuleContainer.resolve(ModuleContainer.java:484)
    at org.eclipse.osgi.container.ModuleContainer.refresh(ModuleContainer.java:1028)
    at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1409)
    at org.eclipse.osgi.container.ModuleContainer$ContainerWiring.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

thanks 
thumbnail
Suresh Nimmakayala, modified 6 Years ago. Liferay Master Posts: 690 Join Date: 8/18/04 Recent Posts
 overriding the Action is missed i guess @Override
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Your Include-Resource directive in the bnd file is highly problematic.
You should never, never, never include things that are provided by Liferay. In this case: All of the packages you list there.

Just remove the line.
thumbnail
saravanan muniraj, modified 6 Years ago. Junior Member Posts: 95 Join Date: 6/1/11 Recent Posts
I took a sample Bladle.autologin code  and add the WShelper class for calling a webservice to validate a cookie.

To resolve the dependency of the class com.sun.xml.ws.developer.WSBindingProvider,com.sun.xml.ws.api.message.Header .

I added the jaxws-rt in gradle file then I got the error -- Unresolved requirement: Import-Package: com.sun.xml.ws.api.message; version=;"2.2.10";

then I added the include thejaxws-rt-2.2.10.jar in BND file, the i got the following error.



2019-09-23 00:22:34.542 INFO [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:261] Processing com.liferay.blade.auto.login-1.0.0.jar
2019-09-23 00:22:41.726 ERROR [fileinstall-D:/Work/Server/liferay-dxp-7.1.10.1-sp1/osgi/modules][org_apache_felix_fileinstall:97] Error while starting bundle: file:/D:/Work/Server/liferay-dxp-7.1.10.1-sp1/osgi/modules/com.liferay.blade.auto.login-1.0.0.jar
org.osgi.framework.BundleException: Could not resolve module: com.liferay.blade.auto.login [1014]_ &nbsp;Unresolved requirement: Import-Package: com.sun.istack_ [Sanitized]<br />
&nbsp;&nbsp; &nbsp;at org.eclipse.osgi.container.Module.start(Module.java:444)<br />
&nbsp;&nbsp; &nbsp;at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)<br />
&nbsp;&nbsp; &nbsp;at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1258)</p>



---------BND File---------

Bundle-SymbolicName: com.liferay.blade.auto.login
Bundle-Version: 1.0.0
-sources: true

Include-Resource:@jaxws-rt-2.2.10.jar


<p>------Gradle------</p>

dependencies {
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "3.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
compileOnly group: "org.osgi", name: "osgi.core", version: "5.0.0"
compile group: 'com.sun.xml.ws', name: 'jaxws-rt',version:'2.2.10'
}




import com.sun.xml.ws.api.message.Header;
import com.sun.xml.ws.api.message.Headers;
import com.sun.xml.ws.developer.WSBindingProvider;




public class WSHelper {
private static Log _log = LogFactoryUtil.getLog(WSHelper.class);

public static void setSecurityHeaders(WSBindingProvider provider, String wsUserName, String wsPwd) {
String SECURITY_NS = http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd;
String PASSWORD_TYPE = http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText;
String AUTH_PREFIX = wss;

try {
SOAPFactory soapFactory = SOAPFactory.newInstance();
/* code logic to add WS authentication */

Header header = Headers.create(security);
provider.setOutboundHeaders(header);
} catch (SOAPException ex) {
_log.error(ex.getMessage());
}
}
}
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Calling webservices is a bit problematic.
I really recommend not including jaxws-rt-2.2.10.jar into your module. You will get into trouble with the jaxws implementation used/provided by Liferay, especially when the versions don't match. Maybe it's doable but it is at least complicated. For most libraries it's not problematic to include them yourself, but libraries that make use of factories & classloading can get you into a dependency hell.
That said:
Let's try to make this deployable.
Please try to remove Include-Resource for the moment, let's try to fix everything in the build.gradle. First, you need to  use the version of jaxws that Liferay provides. I believe, Liferay 7.1 provides 2.1.7. But I am not a 100% sure. (To make sure, search for the jaxws-rt jar in the Liferay folder and check the version)
Please try:
compile group: 'com.sun.xml.ws', name: 'jaxws-rt',version:'2.1.7'
Does this help you? New error?
thumbnail
saravanan muniraj, modified 5 Years ago. Junior Member Posts: 95 Join Date: 6/1/11 Recent Posts
Hi Christoph,The error same after changing the version jaxws-rt',version:'2.1.7
thanks