Adding security to rest api service built with Spring Boot app - rest

I have managed to build a rest api using Spring boot actuator & it works well. I need to now add security to the application and found a link which indicated that all that needs to be done, is to add the following to the pom file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
I tried that and did not get the expected result which was to see the following in the console;
Using default security password: 7dfsdg4d0-4dfsdfsd93-dsdf9f8-axxe1-xxxxxx
Any suggestions or links to solutions, would be appreciated.

I have done this before and it works although I think some versions of Spring Boot have had an issue with this one feature. I was playing with it a little bit and if you copied any of the samples it is possible that you have some other configuration that you have is overriding it. I think this link has good info. Look to ensure you don't have anything in your properties file like "security.user.password" and that you don't have any annotations like #EnableWebSecurity that override any defaults. Let me know if that is helpful and if not maybe you can send a link to GitHub where your code is for someone to take a look.

Related

Cannot use same application for REST call what i have exposed for SOAP service in spring boot

I am trying to create a microservice using spring boot where it will expose REST service. But inside i also want to consume SOAP service. i have created one SOAP service in spring boot but i also i want to use the same application for my REST calls which i am not able to do. When i am hitting the base url, i can clearly see my SOAP service has been exposed correctly. But when i am hitting to a configured request mapping URI, it is failing to reach. I am very little understanding.. but i need your help to get the idea where i am missing big. Thanks in advance.
Please refer to the below screenshots
Working
Rest call mapping
Not working
Though your question lacks many vital informations, I would like to give it a shot.
How does your application.properties look like? Which spring boot version are you using?
If you are on latest spring boot, you can try adding
server.servlet.context-path=/demo to your /resources/application.properties file. That might be the missing piece here.

keycloak admin client on JBOSS AS 7

I am not able to call keycloak-admin-client from JBOSS AS 7.1 REST endpoint. I am able to call the same service from JUNIT test, but when I try to do the same thing from REST endpoint I am having the error:
Caused by:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "access_token" (class org.keycloak.representations.AccessTokenResponse), not marked as ignorable
I am having the same error in JUNIT test when I change the dependency from jackson2 -> jackson
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.0.7.Final</version>
</dependency>
I guess its somehow connected with Jackson provider, but I tried everything from excluding jackson in deployemnt structure to using different, older version of keycloak admin client and keycloak-adapter-bom (2.5.5 or 3.4.3).
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
Can anybody provide working pom.xml for keycloak-admin-client for JBOSS AS 7.1 ?
Many thanks
Thank you #ravthiru for your response.
The problem was more prozaic and simple. I have put the rest endpoint inside the war module, which is secured by keycloak adapter and that prevents the calls to any REST endpoint from outside. I have create separate war module for all REST endpoints associated with Keycloak and it works like charm. Before I called the keycloak admin client just via Unit tests, which means inside from war module and therefore I havent encountered the problem. But it cost me few days to realized where is the problem, cause I was sure it was because of jackson2.
My shame. Cheers.

Accessing Jira Cloud using Unirest Java libraries

I would like to use Unirest Java libraries for accessing Jira Cloud.
Can you share any code snippets? Thank you.
First add the Unirest dependency to your pom.xml (for Maven):
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Then use the following syntax to query JIRA Cloud. Replace yourjira with your instance name and replace with your username and password.
HttpResponse<JsonNode> response = Unirest.get("https://yourjira.atlassian.net/rest/api/2/search?jql=").basicAuth("username","password").asJson();
System.out.println(response.getBody());
More specific JIRA Cloud REST API syntax can be found here:
https://docs.atlassian.com/jira/REST/cloud/

Spring Boot web app deployed to JBoss - webjars-locator does not appear to work

I have a small web app using Spring Boot 1.40 and I am having some issues with webjars-locator. When run on my machine using the embedded Tomcat, the webjars-locator works as expected, and I can access eg. jQuery with the following HTML:
<script src="/webjars/jquery/jquery.min.js" type="text/javascript"></script>
However, when the app is packaged as a .war file and deployed to JBoss 6.4.5, that same HTML no longer works. Trying to directly access the .js file in the browser with that URL results in a 404. However I can use
<script src="/webjars/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
and the file will be found and everything is fine. I am seeing a possibly related log entry when running the app on JBoss:
2016-08-20 02:01:01.154 WARN o.s.w.s.r.ResourceHttpRequestHandler - Locations list is empty. No resources will be served unless a custom ResourceResolver is configured as an alternative to PathResourceResolver.
I'm guessing there's something I need to specifically configure when running in JBoss that "just works" in the embedded Tomcat; if someone could point me in the right direction that would be great.
Having to specify the version of the webjar is not a deal breaker for this particular app, but could be a huge pain in a larger app if we needed to upgrade jQuery or something else.
For context see: https://github.com/webjars/webjars-locator/issues/18
You might just need to add the following dependency:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-jboss-vfs</artifactId>
<version>0.1.0</version>
</dependency>

How to add OpenCV library in spring web application

I have developed a desktop application. It has to upload an image, processing it, and give some out put.(braille image to text). That portion - the desktop application - is working fine. However, now I want to develop it as a web Application. I am currently designing that level.
using SpringMVC and maven.
In here I have added OpenCV as a user library,
but when it run give bellow
error
HTTP Status 500 - Handler processing failed; nested exception is java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path
Help would be appreciated; how to fix this Error?
Thanks,
is this what you're looking for ?
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-4</version>
</dependency>
Cause your question seems a bit odd.
i solved adding opencv_java248.dll file to Windows/Sun/java/bin
added the opencv_java248.dll file to Windows/Sun/java/bin
it is in C:\opencv\build\java\x64 (in my case windows64 bit)