How to integrate Ping Identity SAML with Spring-Boot? - java

I am trying to integrate spring boot with ping identity. I am getting below error while hitting base-URL
ErrorCode: INVALID_ISSUER - Unable to find application for spEntityId:
'http://localhost:8080/sample-sp/saml2/service-provider-metadata/samlexample'
in environment 839268e3-5ccc-4d92-8556-211a062a122b
application.yml
server:
port: 8080
servlet:
context-path: /sample-sp
logging:
level:
root: DEBUG
org.springframework.web: INFO
org.springframework.security: INFO
org.springframework.security.saml: INFO
org.opensaml.xmlsec: TRACE
spring:
security:
saml2:
relyingparty:
registration:
samlexample:
signing:
credentials:
- private-key-location: "classpath:credentials/private.key"
certificate-location: "classpath:credentials/public.cer"
identityprovider:
singlesignon:
sign-request: false
entity-id: demo-saml-eid
sso-url: https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/idp/sso
metadata-uri: https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/metadata/fccace63-397d-43c3-b6bf-605cba6224ba
# verification.credentials:
# - certificate-location: "classpath:credentials/identity-provider-certificate.crt"
Issuer ID
https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b
Single Logout Service
https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/idp/slo
Single Signon Service
https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/idp/sso
IDP Metadata URL
https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/metadata/fccace63-397d-43c3-b6bf-605cba6224ba
Initiate Single Sign-On URL
https://auth.pingone.asia/839268e3-5ccc-4d92-8556-211a062a122b/saml20/idp/startsso?spEntityId=demo-saml-eid

Related

Configure SSH key with Config Server

I am doing a POC on Config Server wherein I will connect to BitBucket repo and if any checkin happen in that repo, my Config Service will pick those changes. In the below code if I am providing bitbucket credentials (hardcoding username and password), its able to connect to BitBucket and everything is working fine. But if I try to provide SSH key, its throwing below error:
application.yml
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${url}
cloud:
config:
server:
git:
cloneOnStart: true
username: username
password: password
default-label: master
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
Like I said the above configuration is working fine. When I replaced with the below configuration.
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${URL}
cloud:
config:
server:
git:
#cloneOnStart: true
ignore-local-ssh-settings: true
hostKey: ${hostKEY}
hostKeyAlgorithm: ssh-rsa
private-key: ${SSH PRIVATE KEY}
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
I am getting below error::
2023-02-10T12:26:39.276+05:30 INFO 24628 --- [ main] c.e.c.ConfigServerApplication : Started ConfigServerApplication in 2.949 seconds (process running for 3.646)
2023-02-10T12:26:41.041+05:30 WARN 24628 --- [2)-10.73.53.175] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: https://bitbucketdc-cluster07.jpmchase.net/scm/ccbrft/ccbrap-config.git: Authentication is required but no CredentialsProvider has been registered
I created SSH Key using command :: ssh-keygen -m PEM -t rsa -b 4096 -C "cigfid_dev#example.com
Any help is appreciated.

Spring Cloud Vault Profile Specific Bootstrap

I have a Spring Boot Application and I would like to Load configurations from Vault based on the Profile I am running. At present i have 2 profiles (dev, prod). My Dev Profile uses a H2 database where as the Prod Profile uses a Posgres DB. Running the dev Profile loads the correct config from Vault but running with the Prod Profile seems to be skipping it somehow and not looking in Vault.
bootstrap.yaml
spring:
application:
name: my-app
profiles:
active:
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
bootstrap-prod.yaml
spring:
application:
name: gateway
profiles:
active: prod
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
For example running the command gradle will load configuration from vault. But running gradle -Pprod fails to load the correct configuration from Vault.
try this syntax to activate your profile when using gradle:
./gradlew clean bootRun --args='--spring.profiles.active=prod'

How to get multiple Consul KVs from different Consul context?

I have these KVs sources store on Consul:
config/books/<key>
config/common/<key>
And in my spring boot app application.yml, I have config it as following:
spring:
application:
name: sampleapp
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: books
I know that this configuration that I made has pointed the app to read from config/books .
But I can't figure out how can I retrieve the Consul KV config from both config/common and config/books.
It's not really flexible there, but it can be done if you rename your project and use defaultContext as well. Based on the documentation Spring Cloud Consul Config takes next paths:
config/testApp,dev/
config/testApp/
config/application,dev/
config/application/
where testApp - name of your app, application - default context
So with the following configuration it will work
spring:
application:
name: books
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: common
Logs after running this configuration:
Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/books/'}, ConsulPropertySource {name='config/common/'}]}

Microservice can't reach config service in docker-compose

I currently have two microservices:
- service - port 8080, this microservice tries to fetch config from the other microservice.
- config - port 8888, this microservice is supposed to provide config.
For some reason my service is unable to fetch configuration from config microservice.
My config microservice should work because I can curl localhost:8888/service/default on my machine I receive:
{"name":"service","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[{"name":"classpath:/shared/service.yml","source":{"server.port":8080,"spring.security.user.password":"admin"}},{"name":"classpath:/shared/service.yaml","source":{"server.port":8080,"spring.security.user.password":"admin"}}]}
Error received (full)
service | 2019-06-06 21:31:06.721 INFO 1 --- [main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://config:8888
service | 2019-06-06 21:31:06.894 INFO 1 --- [main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://config:8888. Will be trying the next url if available
service | 2019-06-06 21:31:06.904 ERROR 1 --- [main] o.s.boot.SpringApplication : Application run failed
Docker-compose.yaml
version: '3.7'
services:
config:
container_name: config
build: ./config
ports:
- 8888:8888
service:
container_name: service
build: ./service
ports:
- 8080:8080
depends_on:
- config
Service Dockerfile:
FROM openjdk:8-jdk-alpine
ADD target/service.jar /app.jar
CMD [ "java", "-Xmx200m", "-jar", "/app.jar" ]
EXPOSE 8080
Service bootstrap.yaml
spring:
application:
name: service
cloud:
config:
uri: http://config:8888
fail-fast: true
service.yaml (has service configuration)
server:
port: 8080
spring:
security:
user:
password: admin # doesnt set since no connection
Config Dockerfile
FROM openjdk:8-jdk-alpine
ADD target/config.jar /app.jar
CMD [ "java", "-Xmx200m", "-jar", "/app.jar" ]
EXPOSE 8888
Config application.yaml
spring:
application:
name: config
profiles:
active: composite
cloud:
config:
server:
composite:
- type: native
search-locations: classpath:/shared
server:
port: 8888
shared/service.yaml (has service configuration)
server:
port: 8080
spring:
security:
user:
password: admin # doesnt set since no connection
Any ideas?
I found some similar issues, although they only had issues with their URI, mine is set correctly.
Microservice can not reach to Config Server on Docker Compose
Docker - SpringConfig - Connection refused to ConfigServer
When one service depends on another you have to make sure that the latter is fully started before connecting to it.
In your case, most probably, config is started but not ready (context started) at the time service is run. As #Ganesh Karewad and #asolanki pointed out, a solution is to implement a reconnection logic. Another solution is to make sure config is initialized and accepting connections before you run service.
You can achieve that with a script that waits until the config app is up. In alternative you could configure the config container with a health check command and after you start it, wait until it is marked as healthy. Then you can run the service container.
Similar issue discussed here and here
Hope that helps.

JHipster - Run spring boot with mvnw command

I am using a JHipster to create a spring boot application with PostgreSQL.
Actualy, when i execute the command mvnw the application-dev config file is "cleaned" to the initial properties.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:
In this case, my database properties (user, password ...) are cleaned. I obtain the error:
"2017-08-06 18:17:10.726 ERROR 10844 --- [ restartedMain]
com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception
during pool initialization.
org.postgresql.util.PSQLException: The server requested password-based
authentication, but no password was provided."
Anyone can help me?
Need to put password into password .
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:<YOUR PASSWORD>

Categories