Migrating ADAL Filter to MSAL on Linux running Java 11 (maven) - AuthenticationResponseParser.parse() throws exception - java-11

in AuthenticationResponseParser.parse(new URI(fullUrl), params);
where params is
Map<String, List<String>>
and is created as
for (String key : httpRequest.getParameterMap().keySet()) {
params.put(key, Collections.singletonList(httpRequest.getParameterMap().get(key)[0]));
}
throws exception
Error: class java.util.Collections$SingletonList cannot be cast to class java.lang.String (java.util.Collections$SingletonList and java.lang.String are in module java.base of loader 'bootstrap')
What could be going wrong?
I am using MSALJ maven dependency com.microsoft.azure, msal4j, 1.13.2
Tried to pass String as params but it is expecting List of strings

Related

Intelij idea exported Java Jar file doesnt work properly java.security.NoSuchAlgorithmException

Hello Everyone!!
I am developing a server app in java lang in intelij idea it works properly
but when exporting as .jar file it gives an error like this
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/javax.net.ssl.DefaultSSLServerSocketFactory.throwException(SSLServerSocketFactory.java:177)
at java.base/javax.net.ssl.DefaultSSLServerSocketFactory.createServerSocket(SSLServerSocketFactory.java:190)
at com.company.ProxyServer.listen(ProxyServer.java:24)
at com.company.ProxyServer.run(ProxyServer.java:18)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1917)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:185)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:110)
at java.base/javax.net.ssl.SSLServerSocketFactory.getDefault(SSLServerSocketFactory.java:74)
... 3 more
Caused by: java.security.KeyManagementException
at java.base/sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(SSLContextImpl.java:942)
at java.base/sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:1111)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at java.base/java.security.Provider$Service.newInstanceOf(Provider.java:1928)
at java.base/java.security.Provider$Service.newInstanceUtil(Provider.java:1935)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1910)
... 8 more
My main class which is Main.java like below it doesn't work and i don't know why?
public class Main{
public static void main(String[] args) {
System.setProperty("javax.net.ssl.keyStore", "files/keystore.jks");
//System.setProperty("javax.net.ssl.trustStore", "files/server.cer");
System.setProperty("javax.net.ssl.keyStorePassword", "12345");
new Thread(new ProxyServer(Utils.SERVER_PORT_TO_LISTEN)).start();
}
}

#Named doesn't resolve the value parameter

After upgrading to micronaut 3.x and replacing the annotation Javax.inject to Jakarta.inject. #Named is unable resolve the property.
import io.micronaut.context.annotation.Bean
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Requires
import java.util.concurrent.ExecutorService
import jakarta.inject.Named
import kotlin.coroutines.CoroutineContext
#Factory
open class ExecutorServiceCoroutineContextFactory {
#Bean
#Requires(missingBeans = [CoroutineContext::class])
fun executorServiceCoroutineContext(#Named("\${coroutines.executor}")executorService: ExecutorService): CoroutineContext {
return ExecutorServiceCoroutineDispatcher(executorService)
}
}
application.yml
coroutines:
executor: coroutines
The resulting error
Message: No bean of type [java.util.concurrent.ExecutorService] exists for the given qualifier: #Named('${coroutines.executor}'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Path Taken: new Controller(Client client,CoroutineContext coroutineContext) --> new Controller(Client client,[CoroutineContext coroutineContext]) --> CoroutineContext.executorServiceCoroutineContext([ExecutorService executorService],String name)
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [executorService] of method [executorServiceCoroutineContext] of class: kotlin.coroutines.CoroutineContext
Hardcoding the value "coroutines" does work but wondering why the code can't resolve it.

Kotlin class servlet provoke NoClassDefFoundError

In a sample Java servlet project in my IntelliJ IDE, i have created this class in Kotlin :
#WebServlet(name = "TwitterAPIServlet", description = "This is used to test the servlet api", urlPatterns = ["/twitterAPIServlet"])
class TwitterAPIServlet : HttpServlet() {
#Throws(IOException::class)
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
// Print answer
val out = resp.writer
out.println("Request Done : </br>")
}
}
When i am trying to call this with my .jsp page, i have this error :
2020-05-10 15:30:34.218:WARN:oejs.HttpChannel:qtp60559178-27: /twitterAPIServlet
java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at main.java.co.rezo.api.internal.v1.TwitterAPIServlet.doGet(TwitterAPIServlet.kt)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
When i am trying the same code in Java, it's working :
#WebServlet(
name = "TwitterAPIServlet",
description = "This is used to test the servlet api",
urlPatterns = "/twitterAPIServlet")
public class TwitterAPIServlet extends HttpServlet {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
out.println("Request Done : </br>");
}
}
What can i do to make my Kotlin code working?
Most probably the issue is that Kotlin's standard library is not included in the generated WAR (or is not on a classpath if you run the exploded app). Make sure to include it in your build.
Instructions for Gradle can be found in the official examples repository: kotlin-examples.
Maven is similar: https://kotlinlang.org/docs/reference/using-maven.html.
In case of pure IDEA (though it's recommended to use one of the build tools above), check the projects settings:
You should see Kotlin's stdlib included in the artifact:

How to configure CXF servlet in Springboot 2.1.1 Final?

PLease find the error I am facing :
In springboot 2.1.1 I am getting below error :
APPLICATION FAILED TO START
Description: Parameter 1 of constructor in
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
required a bean of type
'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath'
that could not be found.
The following candidates were found but could not be injected:
- Bean method 'dispatcherServletRegistration' in 'DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration'
not loaded because DispatcherServlet Registration found non dispatcher
servlet dispatcherServlet
Action:
Consider revisiting the entries above or defining a bean of type
'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath'
in your configuration.
My configuration:
#Configuration
public class CXFConfig {
#Bean
public ServletRegistrationBean dispatcherServlet() {
final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFCdiServlet(), "/services/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
#Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
SpringBus springBus = new SpringBus();
springBus.getInInterceptors().add(new AppInboundInterceptor());
springBus.getOutInterceptors().add(new AppOutboundInterceptor());
return springBus;
}
}
Please confirm how to do the configuration?
dispatcherServlet() method doesn't work in Springboot 2.1.1
I solved this problem by change the method name from dispatcherServlet to disServlet.
Maybe you can try.

spring data elasticsearch Invocation of init method failed; nested exception is java.lang.AbstractMethodError

I have problem with Spring Data Elasticsearch. I configure elasticsearch like this:
#Configuration
#EnableJpaRepositories(basePackages = {"org.project.repositories"})
#EnableElasticsearchRepositories(basePackages = "org.project.repositorieselastic")
#EnableTransactionManagement
public class PersistenceContext {
#Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
}
#Bean
public Client client(){
Settings settings = ImmutableSettings.settingsBuilder()
// Setting "transport.type" enables this module:
.put("cluster.name", "elasticsearch")
.put("client.transport.ignore_cluster_name", false)
.build();
TransportClient client= new TransportClient(settings);
TransportAddress address = new InetSocketTransportAddress("127.0.0.1", 9300);
client.addTransportAddress(address);
return client;
}
}
My repo looks like.
#Repository()
public interface UserFavoriteElasticRepo extends ElasticsearchRepository<UserFavorite, Long> {
}
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.project.repositorieselastic.UserFavoriteElasticRepo org.project.services.elastic.FavoriteIndexerService.elasticRepo; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userFavoriteElasticRepo': Invocation of init method failed; nested exception is java.lang.AbstractMethodError
It's look like the implementation is not generated. But I don't know where to investigate. I tried to use one package and use this - https://github.com/izeye/spring-boot-throwaway-branches/commit/874ccba09189d6ef897bc430c43b6e3705404399 but with no success.
I solved the problem adding this in pom file
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.2.RELEASE</version>
</dependency>
I've got same exception using spring-data-elasticsearch.
But exception was thrown when I declared new methods in repository:
ex.:
public interface UserFavoriteElasticRepo extends ElasticsearchRepository<UserFavorite, Long> {
Page<UserFavorite> findBySomeProperty(String propertyValue, Pageable pageable);
}
It was casued due to spring-data-elasticsearch, spring-data-commons versions. Function declarations have changed: org.springframework.data.repository.query.QueryLookupStrategy.resolveQuery - it caused the exception.
For spring-data-elasticsearch version 2.0.0.RELEASE you have to use spring-data-commons with version 1.12.0.
If you have spring-data-jpa in your project it also uses spring-data-commons. For spring-data-jpa v1.9.0.RELEASE, spring-data-commons is v1.11.0.RELEASE
Could you provide what frameworks and versions of spring you are using? Also If you could put whole stacktrace, it will be helpfull?