Hi I'm using the Which azure-spring-boot-sample-active-directory example to use to validate access token in a Spring Boot application coming from a Vue.js application? 03-resource-server code to validate the token.
But I'm getting an 401 response all the time while using Postman and no Body in response.
what might be the issue? I'm stuck on this for last few days Please do help
Configuration:
#EnableWebSecurity
#Order(SecurityProperties.BASIC_AUTH_ORDER)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
// #formatter:off
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer()
.jwt()
.and();
}
}
Controller :
#RestController
#RequestMapping("/api")
public class HomeController {
#GetMapping("/asd")
#ResponseBody
public String home() {
return "Hello, this is resource server 1.";
}
}
application.yml
spring:
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: https://login.microsoftonline.com/{tenant-id}/discovery/keys
issuer-uri: https://login.microsoftonline.com/{tenant-id}/v2.0
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
Your Java code looks pretty correct. I would start with adding extra logging to your application properties file to see if that tells you anything, eg:
logging:
level:
org:
springframework:
security: DEBUG
Next I would use a JWT viewer to see if there is a nonce field in the JWT header of the access token. If so then it will fail validation - see this recent answer of mine for more info on exposing an API scope in Azure AD.
Finally, you could try another library temporarily and it may give you a better explanation of the cause. See this jose4j code for an example of library based verification. You could paste that into a small Java console app and run it with an Azure access token.
Related
Does anyone have a working example of Stork DNS Service Discovery working in Quarkus.... I see lots of examples using consul but not using DNS and I cannot get the properties or Inject beans when using DNS.
#ApplicationScoped
#RegisterRestClient(baseUri = "stork://auth-service/")
#RegisterProvider(OidcClientRequestFilter.class)
public interface KeycloakService {
I placed the following in my properties file but I get a compiler warning saying it is being ignored.
quarkus.stork.auth-service.service-discovery.type=dns
and my POM
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-discovery-dns</artifactId>
<version>1.2.0</version>
</dependency>
The error I am getting is
Caused by: java.lang.IllegalArgumentException: The value of URL was invalid stork://auth-service
I have a Liferay job written using this guide. I am running liferay-ce-portal-tomcat-7.0-ga3. The job uses DLAppServiceUtil to work with document library.
The job starts exactly as scheduled. But the problem is this exception:
Exception in thread "liferay/scheduler_dispatch-407" java.lang.NoClassDefFoundError: com/liferay/portlet/documentlibrary/service/DLAppServiceUtil
What's wrong?
My pom.xml is:
<!-- ... -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>7.0.0-nightly</version>
<scope>provided</scope>
</dependency>
<!-- ... -->
My job class is:
public class MyJob implements MessageListener {
#Override
public void receive(Message message) throws MessageListenerException {
// DLAppServiceUtil usage...
}
}
How can I fix it?
In Liferay 7, do not use the serviceUtil classes any more (provided you write an OSGi bundle).
Instead add
#Reference
DLAppService dlAppService;
to your component class. Look up how to make the listener a proper OSGi component. Liferay's blade-samples on github might have a template. I am on my phone which makes it hard to look up&explain everything in more detail.
If this doesn't work (as you indicate in your comment), you'll have to check your build process: Make sure that the plugin's Manifest declares the dependencies that it has on the required service. From this you can see that I'm recommending to build OSGi plugins - I'm assuming that you're not doing this, because OSGi would not start your plugin until the dependencies are resolved.
You can do so by utilizing bnd. Check the numerous Maven examples within the blade-samples for more detail.
The classes are no longer part of portal-service, com.liferay.portal.kernel is the correct artifact.
Weird that IDE doesn't complain...
I am consuming Spring Web Service using Spring-ws-core API. But when I am getting error when Add following dependency in my project's pom.xml file :
<!-- SPRING WEB-SERVICE DEPEDENCY INJECTION -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
The exception details is as below :
2015-08-07 03:12:15,097 ERROR | main | org.mortbay.log | Nested in org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-config/netverifier-process-integration.xml]; nested exception is org.springframework.beans.FatalBeanException: Class [org.springframework.integration.config.xml.IntegrationNamespaceHandler] for namespace [http://www.springframework.org/schema/integration] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface:
org.springframework.beans.FatalBeanException: Class [org.springframework.integration.config.xml.IntegrationNamespaceHandler] for namespace [http://www.springframework.org/schema/integration] does not implement the [org.springframework.beans.factory.xml.NamespaceHandler] interface
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:126) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1330) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at
Can anyone please help me to solve this issue ?
I am facing the problem with loading J2K image files (jp2, jp2000) in my java application. What is strange is the fact, that the application runs correctly (the file is successfully read from disk) when it runs as standalone java application (or in tests).
After deployment on Tomcat application server the ImageIO.read(..) method returns null every time.
Any help is appriciated.
Shimon
Update: After reviewing comment from #haraldK - the solution is well described on page https://github.com/haraldk/TwelveMonkeys (section Deploying the plugins in a web app).
You need to define listener in your web.xml:
<web-app ...>
...
<listener>
<display-name>ImageIO service provider loader/unloader</display-name>
<listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
</listener>
...
</web-app>
You also need to add this Maven dependency to your project:
<dependency>
<groupId>com.twelvemonkeys.servlet</groupId>
<artifactId>servlet</artifactId>
<version>3.0.2</version>
</dependency>
Other, less prefered solution is (this was my first solution mentioned here):
After doing some googling I have found this page - https://blog.idrsolutions.com/2013/03/getting-jai-jpeg2000-to-run-on-glassfish-server-without-a-npe/ which discribes problem of resolution of J2K imageio service provider, when using application server such as glassfish or tomcat.
According to this article, the solution is simple. Just use the reader directly:
public BufferedImage getJPEG2000Image(byte[] data){
ImageInputStream iis = null;
BufferedImage image=null;
try {
iis = ImageIO.createImageInputStream(new ByteArrayInputStream(data));
com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderSpi j2kImageReaderSpi = new com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderSpi();
com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader j2kReader = new com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader(j2kImageReaderSpi);
j2kReader.setInput(iis, true);
image = j2kReader.read(0, new com.sun.media.imageio.plugins.jpeg2000.J2KImageReadParam());
}
catch (Exception e){
e.printStackTrace();
}
return image;
}
This Maven dependency is needed as well:
<dependency>
<groupId>com.sun.media</groupId>
<artifactId>jai_imageio</artifactId>
<version>1.1</version>
</dependency>
I am building a web service using seam 2.0.1 and deploying it on jboss 4.2.2 GA. I have my web service class which access another class (updates stuff in data base).
I have standard-jaxws-endpoint-config.xml in META-INF folder.
#Name("pluginHandler")
#Scope(ScopeType.APPLICATION)
#Install(precedence = Install.BUILT_IN)
#Startup(depends = "someclass")
#Stateless
#WebService(name = "Plugin", serviceName = "PluginService")
public class PlugInHandler {
#WebMethod
public int processRequest(Account account)
{
Workbench wb = Component.getInstance("Workbench");
//above line keeps throwing exception "No application context active"
}
}
I have been looking all over different forums, but I cannot find a solution. I tried using Lifecycle.begincall() and Lifecycle.endCall() but nothing worked.
Do I need web.xml as well? If yes what information should web.xml contain?
Any help would be highly appreciated.
I recognize that this is question is rather dated, but to those few poor souls out there that still share your (and, currently my) predicament, here are a few pointers (dragged together from various sources but mainly from https://community.jboss.org/thread/192046):
Java EE WebService
First, using JBoss 4.2.2 likely means using Java EE5. WebServices there (with or without SEAM 2) can only be created on top of Stateless Session Beans. Stateless Session Beans in Java EE 5 need to implement a Service Endpoint Interface annotated with #Local or #Remote. While this has become optional in Java EE6, it is still mandatory here.
So:
#Local
public interface PluginHandlerInterface {
int processRequest(Account account);
}
#WebService
#Stateless
public PluginHandler implements PluginHandlerInterface { }
POJO WebService
If, in seam, you want to use a regular POJO as web-service, your class has to have another special annotation defining a Handler chain:
#WebService
// This here makes all the difference!
#HandlerChain(file = "web-service-handler-chain.xml")
public class PluginHandler {
...
}
This is the handler chain you put in /WEB-INF/classes/web-service-handler-chain.xml:
<?xml version="1.0" encoding="UTF-8"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<description>seam request handler</description>
<!-- probably not necessary
<handler-name>org.jboss.seam.webservice.SOAPRequestHandler</handler-name>
-->
<handler-class>org.jboss.seam.webservice.SOAPRequestHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>
And you have to announce your service class to the war files web.xml like so:
<listener> <!-- this might already be present in your web.xml -->
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<servlet> <!-- Which class is to be used? -->
<servlet-name>PluginHandler</servlet-name>
<servlet-class>your.package.name.PluginHandler</servlet-class>
</servlet>
<servlet-mapping>
<!-- you'll find it under http://localhost:8080/your-war/PluginHandler?wsdl-->
<servlet-name>PluginHandler</servlet-name>
<url-pattern>/PluginHandler</url-pattern>
</servlet-mapping>
So these three steps, creating the handler chain, adding the annotation and announcing your service to the web.xml, should do the trick for you in SEAM: You'll have a web-service and the SEAM Context available right in it.