Anyone experiencing the error messages for failed logins not appearing?
I am upgrading a grails 1.3.7 app to grails 2.1.1 and I have 2 issues with the spring security core functionality.
First, if I try an invalid login the auth fails but there is no error message just {} in the flash message.
Second, I was using a method like this to get the current count of active sessions. It no longer is accurate, as it just increases and doesn't recognize a logout.
def getCurrentSessionCount(){
def sessioncount = 0
sessionRegistry.getAllPrincipals().each{
sessioncount += sessionRegistry.getAllSessions(it, false).size()
}
return sessioncount;
}
Okay well this was a difference in the LoginController how the error messages were getting populated. In 1.3.7 and previous security plugin the code looks like:
msg = SpringSecurityUtils.securityConfig.errors.login.expired
but for 2.1.1 and the upgraded spring security plugin 1.2.7.3 the code needs to use the context like:
msg = g.message(code: "springSecurity.errors.login.disabled")
The session count has to do with a modification to the web.xml that you need to make to add the session listener, however in the new spring 3.0 it was moved so the new entry should look like:
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
Related
I get below error when I consume message in a Jboss ejb container
2022-05-18 22:37:24,699 ERROR [org.jboss.resource.adapter.jms.inflow.JmsActivation] Unable to reconnect org.jboss.resource.adapter.jms.inflow.JmsActivationSpec#8315a9(ra=org.jboss.resource.adapter.jms.JmsResourceAdapter#10a62f0 destination=queues/Subscriber.global.globalvirtual.e2e.cmdm.changepub.Virtual destinationType=javax.jms.Queue tx=true durable=false reconnect=10 provider=java:/ACTIVEMQJMSNONXAProviderAsync user=ldcp.cmdm pass= )
javax.jms.JMSException: Please enable transactions on PulsarConnectionFactory with enableTransaction=true
After getting this error - I set enableTransaction=true and started getting different error
javax.jms.JMSException: not supported
at com.datastax.oss.pulsar.jms.PulsarConnection.createConnectionConsumer(PulsarConnection.java:685)
the error is in createConnectionConsumer.
This is the method called by the JBoss container.
This method is currently not implemented
https://github.com/datastax/pulsar-jms/blob/96606d0f22a1af8fdde0c5eff0f5dde086d9862c/pulsar-jms/src/main/java/com/datastax/oss/pulsar/jms/PulsarConnection.java#L685
the implementation should be quite straighforward.
There are integration tests for Payara and Apache TomEE but JBoss is still not covered.
Please open an issue on github.
I have a java ee 8 web app using deltaspike using core, data and jsf modules.
I also added cdi bean (RegisterService using #trasactional) which calls a UserRepository
public void createNewUser(User newUser){
try{
userRepository.save(newUser)
}catch(PersistenceException ex){
throw new RegisterException("Error", ex); //it never falls at this point
}
}
When service layer calls repository I’m catching a PersistenceException and rethrowing a service layer exception but the repository never throws PersistenceException even if the primary ID is duplicated (I just can see the stacktrace in console output), of course I’m running into a contraint exception to try to execute the expected flow
I’m using a deltaspike exception handler but I have not added a #handler for PersistenceException
Does somebody knows what could be happening here?
this is a reproducible example: https://github.com/gdiazs/javaee8-fullstack
Since there is no tables in DB it will throw an PersitenceException.
I ran this example in 2 laptops.
Mine: OSx 10.14.6
JDK: Open JDK Zulu 1.8
eclipse and also maven terminal execution
Work: OSx 10.14.6 (it works as I expect good here)
JDK: Oracle 1.8
Intellij and also maven terminal execution
So now I`m really confused, no idea why is working just in one.
Scenario: I have 3 spring cloud streaming apps
1'st: unmarshalls XML payload into JAXB object
2'nd: Converts JAXB payload into our domain POJO
3'rd: Validate domain object
I am trying to test the 3'rd app. I have included the 1'st and 2'nd applications as test dependencies. I have added:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
Now I have about 20 xml files with various validation scenario's. The first test works fine. I am able pick up the expected message of the channel using:
final Message<PaymentInstruction> mceMessage =
(Message<PaymentInstruction>) collector.forChannel(
validationBindings.mce()).take();
The 2'nd test that is run is where I have an issue. The test just sits at 'take'.
I have done some digging in the spring-integration-core-4.3.8.jar and have traced the issue to org.springframework.integration.dispatcher.AbstractDispatcher:
#Override
public synchronized boolean addHandler(MessageHandler handler) {
Assert.notNull(handler, "handler must not be null");
Assert.isTrue(this.handlers.size() < this.maxSubscribers, "Maximum subscribers exceeded");
boolean added = this.handlers.add(handler);
if (this.handlers.size() == 1) {
this.theOneHandler = handler;
}
else {
this.theOneHandler = null;
}
return added;
}
There is a handler that was added for the first test, so it assigns null to 'this.theOneHandler'
My options are:
Refactor the code in the other 2 projects so that I can do the unmarshalling and creating of my domain object without the need for the spring cloud app code
I can create an individual unit test class per test case, however I'd rather not go this route as the startup time for spring boot will be high that will be multiplied by the number of test cases
Do I have some missing configuration that would allow me to have these multiple handlers or am I breaking the way I want to use spring cloud streaming?
Environment:
Java 8 Update 131
org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE
org.springframework.boot:spring-boot-dependencies:1.5.2.RELEASE
theOneHandler is a dispatching optimization used when a channel has only one subscriber.
It sounds like you are binding all your services to the same channel, which is not what you want.
Bottom line is you can't do what you are trying to do because each of the services are using the same channel name (presumably input).
You would need to load each service in a separate application context and wire them together with bridges.
EDIT
You could also test them using an aggregated application.
After looking through the documentation and trying to find other examples of developers getting this error, I am a bit stuck. We are working with NServiceBus 6 and are occasionally getting a System.MethodAccessException in our message handlers on the call to return Task.CompletedTask. It seems to only occur when the handler is deployed in an Azure Worker Role (as opposed to running in the emulator). We are using the Azure Service Bus transport.
public Task Handle(UpdatePatientAccommodationCode message, IMessageHandlerContext context)
{
Console.WriteLine($"Handling [{message.GetType()}]");
var patientVisit = LoadByExternalPatientId(message.ClientId, message.ExternalPatientId);
var mappedEvent = patientVisit.HandleCommand(message);
if (patientVisit.IsEventAdded)
PatientVisitEventStore.Save(patientVisit);
return mappedEvent == null ? Task.CompletedTask : context.Publish(mappedEvent);
}
The actual exception looks like this:
System.MethodAccessException: Attempt by method 'XXX.Handlers.PatientVisitHandler.Handle(XXX.UpdatePatientAccommodationCode, NServiceBus.IMessageHandlerContext)' to access method 'System.Threading.Tasks.Task.get_CompletedTask()' failed.
at XXX.Handlers.PatientVisitHandler.Handle(UpdatePatientAccomm odationCode message, IMessageHandlerContext context) in PatientVisitHandler.cs: line 314
at NServiceBus.InvokeHandlerTerminator.Terminate(IInvokeHandlerContext context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\Incoming\Invok eHandlerTerminator.cs: line 24
at NServiceBus.LoadHandlersConnector.<Invoke>d__1.MoveNext() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\Incoming\LoadH andlersConnector.cs: line 40
I suspect your code locally has .NET framework 4.6.x which supports Task.CompletedTask. When you deploy to CS and use OS family less than version 5 won't have support for 4.6.x You either will need to use a startup task to install 4.6.x or migrate to OS Family 5 (Server 2016).
That is strange. Judging by the reference sources of Task.CompletedTask I can't come up with a scenario where this could happen. The task that is statically cached is initialized with RAN_TO_COMPLETION and DO_NOT_DISPOSE. Based on that I would suggest you determine whether you are using the .NET Framework version 4.6 or higher. If you do and you still see the exception try to replace Task.CompletedTask with
static class TaskEx
{
public static readonly Task CompletedTask = Task.FromResult(0);
}
I've enabled Caching in my Spring app and I use Redis to serve the purpose.
However, whenever a connection failure occurs, the app stops working whereas I think it had better
skip the Caching and go on with normal execution flow.
So, does anyone have any idea on how to gracefully do it in Spring ?
Here is the exception I got.
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
As from Spring Framework 4.1, there is a CacheErrorHandler that you can implement to handle such exceptions. Refer to the javadoc for more details.
You can register it by having your #Configuration class extends CachingConfigurerSupport (see errorHandler()).
You can use CacheErrorHandler as suggested by Stephane Nicoll. But you should make sure to make
RedisCacheManager transactionAware to false in your Redis Cache Config(to make sure the transaction is committed early when executing the caching part and the error is caught by CacheErrorHandler and don't wait until the end of the execution which skips CacheErrorHandler part). The function to set transactionAware to false looks like this:
#Bean
public RedisCacheManager redisCacheManager(LettuceConnectionFactory lettuceConnectionFactory) {
JdkSerializationRedisSerializer redisSerializer = new JdkSerializationRedisSerializer(getClass().getClassLoader());
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofHours(redisDataTTL))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer));
redisCacheConfiguration.usePrefix();
RedisCacheManager redisCacheManager = RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(lettuceConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.build();
redisCacheManager.setTransactionAware(false);
return redisCacheManager;
}
Similar to what Stephane has mentioned, I have done in by consuming the error in try catch block. Adding a fall back mechanism where if Redis is not up or may be the data is not present then I fetch the data from DB.(Later if I find one then I add the same data in Redis,if it is up to maintain consistency.)