generator-jhipster-multitenancy
generator-jhipster-multitenancy copied to clipboard
exception while setting password after invite on non-logged in browser.
I'm taking 1.0.3 for a spin against 5.7.
I created a new "customer" (my tenant entity ). all good.
Then I created a new user via the hipster admin tool assigned to this customer. This worked as well.
I didn't have email configured, so the email send failed. However, I pulled the create a password email out of the log files ad used the embedded link to attempt to create a password.
A key thing here is that I used a DIFFERENT BROWSER for this last process. so this new browser didn't have a currently logged in user.
And this failed to work. The exception at the bottom was in the logs.
My rather inexperienced analysis:
Ideally the user lookup should occur based on the "token" sent in the email and not via the currently logged in user. However in this case, the AOP is "before" execution. so the user lookup (via said token) which should occur in UserService.completePasswordReset has not run.
I'm going to guess (and I could be WAY WAY wrong here) that in the case of the completePasswordReset() method, the cutpoint for the AOP may have to be after execution, so that the user ( and therefore customer) can be looked up. Or, perhaps, simply exclude this method ?
The exception is as follows:
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at com.example.aa.aop.customer.CustomerAspect.beforeExecution(CustomerAspect.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:626)
at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:44)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.example.aa.service.UserService$$EnhancerBySpringCGLIB$$2ad0da7e.completePasswordReset(<generated>)
at com.example.aa.web.rest.AccountResource.finishPasswordReset(AccountResource.java:177)
at com.example.aa.web.rest.AccountResource$$FastClassBySpringCGLIB$$d40de086.invoke(<generated>)
and the aspect code in question:
45 User user = userRepository.findOneByLogin(login.get()).get();
come from the following template:
if(login.isPresent()) {
User user = userRepository.findOneByLogin(login.get()).get();
if (user.get<%= tenantNameUpperFirst %>() != null) {
Filter filter = entityManager.unwrap(Session.class).enableFilter("<%= tenantNameUpperCase %>_FILTER");
filter.setParameter(fieldName, user.get<%= tenantNameUpperFirst %>().getId());
}
}