Issue in migrating OAuth2 SSO provider of Spring boot application from one provider to another - spring-boot

I am working with migrating OAuth2 SSO provider for my Spring boot application from SSOProvider1 to SSOProvider2.
My application has been working fine with SSOProvider1. The relevant properties are as follows:
spring.security.oauth2.client.registration.ssprovider1.client-id=abcd
spring.security.oauth2.client.registration.ssprovider1.client-secret=1234
spring.security.oauth2.client.registration.ssprovider1.scope=api
spring.security.oauth2.client.registration.ssprovider1.client-authentication-method=basic
spring.security.oauth2.client.registration.ssprovider1.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.ssprovider1.token-uri=https://ssoprovidr1.base.com/token
spring.security.oauth2.client.provider.ssprovider1.authorization-uri=https://ssoprovidr1.base.com/authorize
spring.security.oauth2.client.provider.ssprovider1.user-info-uri=https://ssoprovidr1.base.com/userinfo
spring.security.oauth2.client.provider.ssprovider1.user-name-attribute=name
Now, as part of migration, for SSOProvider2, I have changed only following values:
spring.security.oauth2.client.registration.ssprovider2.client-id=efgh
spring.security.oauth2.client.registration.ssprovider1.client-secret=5678
spring.security.oauth2.client.registration.ssprovider2.scope=read
spring.security.oauth2.client.registration.ssprovider2.client-authentication-method=basic
spring.security.oauth2.client.registration.ssprovider2.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.ssprovider2.token-uri=https://ssoprovidr2.base.com/token
spring.security.oauth2.client.provider.ssprovider2.authorization-uri=https://ssoprovidr2.base.com/authorize
But, whenever I am starting my app and browsing the end-point, I am getting following error: Too many redirect and clearing the browser cookies also did not help.
I am not sure, why I am getting this error.
Could anyone please help here? Thanks.

Related

Spring Security with SOAP web service is working in Tomcat, but not in WebLogic

I have created a sample SOAP Web Service project (spring boot) and trying to integrate Okta as a resource server for authentication.
I am able to deploy the application to WebLogic, but when testing the service using SOAP UI, it gives the response even when there is no Token included in the header.
When I access WSDL from a browser using my wsdl url, http://myhost:port/appservice/app.wsdl I see the 401 error, so I think it is picking up the Security config changes. But it is not working for SOAP requests, I would get response even with out Okta token.
Is it because for SOAP requests, do I need to include any interceptors on top of Security Config java file. Or am I taking a wrong path for security with SOAP. Can someone let me know what am I missing or point me to right direction. Is token validation part of WS-Security? or the authentication manager in Okta resource server enough for this?
I followed this documentation to create it.
I have read most of the SO questions related to this and spring documentation, but could not connect the missing dots. Please help me with this. After spending lot of time, I felt like I was moving in circles.
UPDATE:
I have enabled spring security debug logs by doing below
#EnableWebSecurity(debug=true)
logging.level.org.springframework.security.web.FilterChainProxy=DEBUG
UPDATE2:
I haven't made any big changes to my configuration, but when I ran the project on embedded tomcat locally, it started working. To run on Tomcat, I changed packaging from war to jar, excluded Tomcat in my POM and in my Main class, I had to remove the SpringBootServletInitializer and WebApplicationInitializer. That's it. I tested SOAP UI with the Okta bearer token and it gave me response. With out the token it did not give me response.
Spring Security not working only in case of WebLogic12c. I don't know what I am missing to include for that to work in WebLogic. when deployed through Tomcat, request is passed through all the beans in Security Filter Chain {
WebAsyncManagerIntegrationFilter,
SecurityContextPersistenceFilter,
HeaderWriterFilter,
CsrfFilter,
LogoutFilter,
BearerTokenAuthenticationFilter,
RequestCacheAwareFilter,
SecurityContextHolderAwareRequestFilter,
AnonymousAuthenticationFilter,
SessionManagementFilter,
ExceptionTranslationFilter,
FilterSecurityInterceptor}
But on WebLogic, the request is passed only through first four beans in Security Filter Chain {WebAsyncManagerIntegrationFilter,
SecurityContextPersistenceFilter,
HeaderWriterFilter,
CsrfFilter}
I just wanted to update the alternate solution I found for this problem, for completeness.
Spring Security Filter chain was not working for Weblogic, where as same was working in Tomcat, even for Weblogic version 12.2.1.4.
I had followed this example, and implemented Okta filter as spring boot version was not working in Weblogic 12.2.1.4.
Thanks to #Toerktumlare, I have implemented logging with logback-spring.xml

spring boot multiple servers login issue

We have a spring boot project used to use only one server. We recently switching to use two servers for the same spring boot application. Now the users are frequently asked to login. We found out if a user logged in one server and a new request is sent to another server, this would happen.
I am sure this is very common issue with solutions. Could anyone point me to the right direction how to fix the login issue? Thanks a lot!

Getting 401 for Spring Boot API after login to keycloak.But its work if user didn't sign in to keycloak

I'm using Spring Boot + Keycloak + Angular for my application and keycloak-spring-boot-starter uses for the backend. But this is working perfectly on my computer and when I deploy this
Without logging to the system system works perfectly
When login to the system using angular app and make a api request getting 401 from Spring boot backend
In postman without token it gives results
In postman with the token it gives 401
But on angular side (frontend) Authentification and Authorization work perfectly. Further, I have tried to run this application in the machine(angular and Spring boot run in my local machine similar environment to production) using deployed keycloak, it also works perfectly.
Since there is no related error in the console I'm really worried about how to figure out the issue. I'm kindly requesting you to help me regarding this.
Actually, it was my mistake I have set SSL to none in Keycloak configuration but Spring Boot app I have set to external. Therefore it works on my computer and when I deploy it, it didn't work.

Keycloak 3.4.3 and springboot 2.0

Hi, I am trying to use single-sign on with keycloak and springboot 2 app
I got local keycloak setup realm and client.
I followed this example : spring-boot-keycloak-tutorial
This works fine, my issue is that I want to implement single sign on. Which means I don't want the user to login using keycloak login page.
If the users are logged in to the network (using Windows machine), and try to access the page, then they should be able to access the application without login because they are valid network users.
I don't seem to find an example on how to setup SSO and pass the credentials directly from windows to keycloak
You can configure your realm to use Kerberos user federation. This will enable SSO using the active directory.
See the official example page
You then need to make sure that your browser to support the SSO.
It turned out that the keycloak-spring-boot-adapter does not work for spring boot 2.0+
I changed my spring version to 1.5.3 instead of 2.0.5 and this solved the problem.
I am not sure if there is an alternative for spring boot 2.0

How to configure Spring Boot Tomcat Basic Auth together with Spring Security?

I'm currently trying to make a Spring Boot app. I've managed to create successfully user authentication using LDAP and custom logic.
However, I'm trying to add another layer of security on top of that, something like "htaccess" to prevent unauthorized users from even seeing the web page (client requirement), as well as stop Google from indexing the page. This can be a single predefined user (doesn't need to be connected to ldap auth).
I've read about configuring the tomcat realm, tomcat-users etc. but since it's Spring Boot app with embedded tomcat, I can't find a place to successfully configure it.
Does anyone have any idea how to create such setup?

Resources