Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Omkar Khandare
I need to assign conditional custom role while creating account by stranger
12 de febrero de 2013 7:53
Respuesta

Omkar Khandare

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 6 de marzo de 2012

Mensajes recientes

I am calling create account.jsp page from different pages for registration.
i am appending some parameter with it.
e.g.
type=Role 1
or
type=Role 2
as per such parameter i want make user create their account with specific Role which is already predefined by Administrator.

I am currently using hook plugin to override create_account.jsp page,
i have tried with ext plugin also but unable set role for User object before create account action call.

So how should i assign user a specific role rather than a default role i.e. Power User.?

Please Help.
Meera Prince
RE: I need to assign conditional custom role while creating account by stra
12 de febrero de 2013 22:22
Respuesta

Meera Prince

Ranking: Liferay Master

Mensajes: 820

Fecha de incorporación: 8 de febrero de 2011

Mensajes recientes

Hi Omkar Khandare,

create_account.jsp you can create select box there you can populate roles according to your parameter.
once user select the the role once he submit take the role and assign to him.

this should work for ext only we cant do in plugin because we need to customize CreataAccountAction.java class


Regards,
Meera Prince
Omkar Khandare
I need to assign conditional custom role while creating account by stranger
12 de febrero de 2013 23:06
Respuesta

Omkar Khandare

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 6 de marzo de 2012

Mensajes recientes

I found CreateAccountAction.java source code from web,
Now i am using same with custom role modifications using Struts action override by through hook.
my refe.URL for steps of overriding existing struts action is

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen06-overriding-and-adding-struts-actions-0

I kept all source code as it is.

& edited liferay-hook.xml file as given on liferay docs as.

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<struts-action>
<struts-action-path>/login/create_account</struts-action-path>
<struts-action-impl>com.liferay.portlet.login.action.CreateAccountAction</struts-action-impl>
</struts-action>
</hook>


but getting an exception as follows..

06:52:32,734 INFO [pool-2-thread-29][HookHotDeployListener:550] Registering hook for sa-public-registration-hook
06:52:32,890 ERROR [pool-2-thread-29][HotDeployImpl:191] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for sa-public-registration-hook
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for sa-public-registration-hook
at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:276)
at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:188)
at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:27)
at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:151)
at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:141)
at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:64)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:56)
at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:52)
at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:103)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/struts/PortletAction
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:52)
at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:27)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initStrutsAction(HookHotDeployListener.java:2138)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initStrutsActions(HookHotDeployListener.java:2198)
at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:628)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:273)
... 24 more
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.struts.PortletAction
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
... 38 more

Can anyone tell me how to resolve it.
Gnaniyar Zubair
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 1:36
Respuesta

Gnaniyar Zubair

Ranking: Liferay Master

Mensajes: 603

Fecha de incorporación: 19 de diciembre de 2007

Mensajes recientes

Instead of HOOK, EXT plugin will suit for your requirement it seems which have full control.

Extend addUser method of CreateAccountAction.java


1. Define Role Names in property file
2. Get the Role Name in CreateAccountAction from property
Role role = RoleLocalServiceUtil.getRole(company.getCompanyId(), PropsUtil.get("my.custom.role"));


3. After adding the user, just assign

UserLocalServiceUtil.addRoleUsers(role.getRoleId(), userId);
Meera Prince
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 3:48
Respuesta

Meera Prince

Ranking: Liferay Master

Mensajes: 820

Fecha de incorporación: 8 de febrero de 2011

Mensajes recientes

HI The following link is example for how to override struts actions,

https://github.com/liferay/liferay-plugins/tree/master/hooks/sample-struts-action-hook


Regards,
Meera Prince
Omkar Khandare
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 20:28
Respuesta

Omkar Khandare

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 6 de marzo de 2012

Mensajes recientes

i have started using ext plugin

i have overriding only addUser method through extending CreateAccount class
my method get called but.

i am getting an exception as follows.

ERROR [http-bio-8080-exec-4][render_portlet_jsp:154] com.liferay.portal.security.auth.PrincipalException
at com.liferay.portal.service.permission.RolePermissionImpl.check(RolePermissionImpl.java:31)
at com.liferay.portal.service.permission.RolePermissionUtil.check(RolePermissionUtil.java:30)
at com.liferay.portal.service.impl.UserServiceImpl.checkRoles(UserServiceImpl.java:1872)
at com.liferay.portal.service.impl.UserServiceImpl.checkAddUserPermission(UserServiceImpl.java:1709)
at com.liferay.portal.service.impl.UserServiceImpl.addUserWithWorkflow(UserServiceImpl.java:456)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at com.liferay.portal.service.UserServiceUtil.addUserWithWorkflow(UserServiceUtil.java:372)

Plz Help.
Meera Prince
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 20:34
Respuesta

Meera Prince

Ranking: Liferay Master

Mensajes: 820

Fecha de incorporación: 8 de febrero de 2011

Mensajes recientes

HI
To avoid PrincipalException we should call LocalServiceUtil class methods not serviceUtils. Use UserLocalServiceIUtil class instead of UserServiceIUtil .

If use RoleSrviceUtil then use RoleLocalServiceUtils.

Regards,
Meera Prince
http://www.liferaysavvy.com/
Omkar Khandare
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 22:17
Respuesta

Omkar Khandare

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 6 de marzo de 2012

Mensajes recientes

now i am using

UserLocalServiceUtil.addUserWithWorkflow(...)

instead of UserServiceUtil.addUserWithWorkflow(...)

but i dont have two additional parameters values for
1.creatorUserId
2.locale

except these we got all in CreateAccountAction

Now when i submit my form it shows error as

Your request failed to complete

NOT any exception on console..
even i set creatorUserId as Administrator userID from user_ table
& setting locale through LocaleUtil.getDefault()

but still same error on sign in page.

What should i do now.?
Meera Prince
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 22:51
Respuesta

Meera Prince

Ranking: Liferay Master

Mensajes: 820

Fecha de incorporación: 8 de febrero de 2011

Mensajes recientes

HI
Send me your Exception StackTrace.

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
locale=themeDisplay.getLocale();
creatorUserId=give admin id10169


Regards,
Meera Prince
Omkar Khandare
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 23:01
Respuesta

Omkar Khandare

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 6 de marzo de 2012

Mensajes recientes

Thats a problem that i dont have any stack trace..

but i realized that..
my method giving an error on putting before and after comments everywhere.

my method in addUser method of my EXT plugin class.

User user = UserLocalServiceUtil.addUserWithWorkflow(0, company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

is not executing properly & giving error.

On create account form submission i am only getting error as
Your request failed to complete

on jsp page of create account form.

Please help.
emoticon
Meera Prince
RE: I need to assign conditional custom role while creating account by stra
13 de febrero de 2013 23:12
Respuesta

Meera Prince

Ranking: Liferay Master

Mensajes: 820

Fecha de incorporación: 8 de febrero de 2011

Mensajes recientes

Hi place that code inside
try{

User user = UserLocalServiceUtil.addUserWithWorkflow(0, company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
}catch(Exception e){

e.printTrackTrace();
}

Regards,
Meera Prince