Git Product home page Git Product logo

identity-sample-apps's Introduction

Pivotal Single Sign-On Service Sample Applications

This repo holds separate sample applications for each one of the four OAuth 2.0 grant types supported by the Pivotal Single Sign-On Service. The grant type specific environment variables are configured to their relevant values in the manifests of sample application. Each grant type maps to an Application Type as seen in the Pivotal Single Sign-On Service Dashboard. For more information about how to determine SSO Application Type, please read PCF SSO Documentation.

Application Type Grant Type Pivotal SSO Version Spring Cloud SSO Starter library version
Web App authorization_code any 1.1.2.RELEASE
Service-to-Service App client_credentials any 1.1.2.RELEASE
Web & Service-to-Service App authorization_code, client_credentials v1.10+ 1.1.2.RELEASE
Resource Server App n/a any n/a

The latest version of this repository supports the following dependencies:

Dependency Version
Spring Boot 2.3.4+
Spring Security 5.3.4+
Spring Cloud SSO Starter library 1.1.2.RELEASE

The sample apps using Spring Boot 1.5 and Spring Security 2 is located on the spring-boot-1.5 branch.

The sample apps using Spring Boot 2.1 and Spring Security 5.1 is located on the spring-boot-2.1 branch.

The sample applications for the corresponding grant types are located in subdirectories of this project:

Prerequisites

  1. Login as a Space Developer into the required Org and Space on your PCF Foundation

    cf login -a api.<your-domain>
    
  2. Ensure that an SSO (p-identity) Service Plan exists for your Org. Record the name of the plan you wish to select to be used as the <plan_tier> value for the next step.

    cf marketplace | grep p-identity
    
  3. Create a Service Instance named 'p-identity-instance' from the 'p-identity' service using an available Service Plan

    cf create-service p-identity <plan_tier> p-identity-instance
    

You can deploy the authcode and resource server sample applications using application bootstrapping with the steps below. You can read more about these topics in the following sections.

Deploying Resource Server Sample App

  1. Navigate to the resource-server directory

  2. Update the SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI <PLAN_AUTH_DOMAIN> and <YOUR_DOMAIN> placeholders in the resource-service manifest.

  3. Build (./gradlew build) and push (cf push) the resource-server application. (You may have to use --random-route flag when cf pushing your application if a route already exists with your application name.)

Deploying Authorization Code Sample App

  1. Navigate to the authcode directory

  2. Update the RESOURCE_URL value in the authcode manifest.yml file to the route of the deployed resource-server (which you can find by running cf apps).

  3. Build (./gradlew build) and push (cf push) the authcode project. (You may have to use --random-route flag when cf pushing your application if a route already exists with your application name.) The sample application will be immediately bound to the SSO Service after cf push.

Deploying Client Credentials Sample App

  1. Navigate to the client-credentials directory

  2. Update the RESOURCE_URL value in the client-credentials manifest.yml file to the route of the deployed resource-server (which you can find by running cf apps).

  3. Build (./gradlew build) and push (cf push) the client-credentials project. (You may have to use --random-route flag when cf pushing your application if a route already exists with your application name.) The sample application will be immediately bound to the SSO Service after cf push.

Deploying Authorization Code & Client Credentials Sample App

  1. Navigate to the authcode-client-credentials directory

  2. Update the RESOURCE_URL value in the authcode-client-credentials manifest.yml file to the route of the deployed resource-server (which you can find by running cf apps).

  3. Build (./gradlew build) and push (cf push) the authcode-client-credentials project. (You may have to use --random-route flag when cf pushing your application if a route already exists with your application name.) The sample application will be immediately bound to the SSO Service after cf push.

Testing the Sample Apps

  1. Preparing a test user with sufficient scopes

    Contact your cloud administrator to determine whether your Service Plan is has configured the "Internal User Store" as an Identity Provider or an external Identity Provider (like LDAP).

    • If your SSO Service plans is configured with the 'Internal User Store' option, you can use the instruction in Manage Users in an Internal User Store documentation to create a user to todo.read and todo.write scopes.

    • If your plan is configured with an alternative Identity Provider (like LDAP), your administrator will need to provide you credentials with memberships to the todo.read and todo.write scopes.

  2. Visit the deployed sample apps by entering the urls of the apps (which you can find by running cf apps). (The Resource Server sample app is a backend API and not intended to be accessed through a browser.)

Unsupported Grant Types

Implicit Grant Type:

The Implicit Grant Type is supported by Spring Security 5, but has generally fallen out of favor as an architectural pattern for SPAs. It has been determined that we will not provide Sample Apps to demonstrate this grant type moving forward. The current recommendation for SPAs is to use the Authorization Code Flow in conjuntion with the Proof Key for Code Exchange to protect the Authorization Code in the client's browser. For more information, please see the Okta developers blog article: Is The OAuth Implict Flow Dead.

Resource Owner Password Credentials (i.e. Password) Type:

The Resource Owner Password Credentials grant type is no longer supported by Spring Security 5 (see the Grant Type Support Matrix). The Password grant type is more commonly used with programs, like CLIs, that are unlikley to be dependendant on Spring or other Web based software libraries. For more information, see the OAuth 2 Password Grant specification.

If your use cases require the Password grant type for a Spring application, you will need to implement the access token request on your own. However, if your Java based CF application is bound to an SSO service instance and using the Spring Boot SSO Starter Library, you may find it useful to reference the table of Spring Security 5 Java properties built from VCAP_SERVICES to help craft your request.

Bootstrap Application Client Configurations for the Pivotal Single Sign-On Service Instance

Beginning in SSO 1.4.0, you can set environment variables in your application's manifest to bootstrap client configurations for your applications automatically when binding or rebinding your application to the service instance. These values will be automatically populated to the client configurations for your application through CF environment variables.

NOTE: These configurations are only applied at the initial service binding time. Subsequent cf push of the application will NOT update the configurations. You will either need to manually update the configurations via the SSO dashboard or unbind and rebind the service instance.

When you specify your own scopes and authorities, consider including openid for scopes on auth code, implicit, and password grant type applications, and uaa.resource for client credentials grant type applications, as these will not be provided if they are not specified.

The table in SSO Documentation - Configure SSO Properties with Environment Variables provides a description and the default values. Further details and examples are provided in the sample application manifests.

To remove any variables set through bootstrapping, you must use cf unset-env <APP_NAME> <PROPERTY_NAME> and rebind the application.


Running in Unsafe Environment with Self-signed Certificates

⚠️⚠️⚠️ WARNING ⚠️⚠️⚠️ Do not use the following steps in your production environments; instead, use trusted certificates within your environment.

If necessary to push the sample apps to an unsafe environment with self-signed certificates, you can add the cloudfoundry-certificate-truster dependency to the gradle file. Follow the instructions from the cloudfoundry-certificate-truster readme.

identity-sample-apps's People

Contributors

ajackson avatar andrewedstrom avatar cameronmoreau avatar cbguder avatar cdutra avatar cf-identity avatar cf-uaa avatar cfryanr avatar changdrew avatar clairethompson avatar datianshi avatar dependabot-preview[bot] avatar fhanik avatar jhamon avatar khuang-pivotal avatar lesliecodes avatar margocrawf avatar mbhave avatar medvedzver avatar priyata25 avatar samsamskies avatar sreetummidi avatar tnwang avatar tylerschultz avatar willsu avatar wschaefer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

identity-sample-apps's Issues

Auto rotate client secrets for service-to-service apps

Thank you for making Pivotal Cloud Foundry such a great product. I was uncertain were I could post this question. So I ask it here.

We have a requirement to automatically rotate app secrets every month for all our application.
If possible we still want to use the SSO Dashboard and tile to ensure easy setup and management of the applications service-to-service credentials.

Is there an easy way of ensuring that all the applications registered through the SSO-Tile get their secrets rotated without any manual interventions?

We do not want to push buttons or use the SSO-Dashboard as it would very quickly become a maintenance nightmare to ensure all 300 apps get their client secrets rotated every month.

I already read: https://docs.pivotal.io/p-identity/1-10/configure-apps/#-regenerate-an-app-secret
and I am aware that I can delete an recreate the service binding, but that means that I also would lose any scopes given to the service-to-service applications and that I would have to login to the SSO Dashboard to re-select the scopes needed for the service-to-service app after recreating the service binding.

I use SSO_RESOURCES and SSO_AUTO_APPROVED_SCOPES in my app manifest to set which scopes the service-to-service app should have, but once I unbind and recreate the service bindings the scopes that I once approved for the app, is gone. This makes secret rotation quite cumbersome. The scopes and authorities I am using is only used within the space where I have created my SSO service instance and I am using SSO v. 1.10

Maybe it is possible for the app secret and VCAP_SERVICES vars to get updated with rotated app secrets when the apps are restaged. Perhaps I could just even create a deployment script that read out the p-identity client_id and updated the client_id with the missing scopes during deploy, but I am unsure how I best should do any of that without messing up the management possibilities that the SSO-Dashboard provides.

Error "java.lang.IllegalArgumentException: URI is not absolute“ when 'cf push' resource server

Hi,

I got the following error when run 'cf push' resource server. Could you help check?

2016-10-12T01:32:37.65+0000 [APP/0] OUT org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.oauth2.provider.token.TokenStore org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration.tokenStore; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenStore' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.TokenStore]: Factory method 'jwtTokenStore' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenEnhancer' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter]: Factory method 'jwtTokenEnhancer' threw exception; nested exception is java.lang.IllegalArgumentException: URI is not absolute 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060) ~[spring-context-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199) ~[spring-web-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:109) ~[tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4658) [tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5277) [tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.33.jar!/:8.0.33] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_71-] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_71-] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_71-] 2016-10-12T01:32:37.65+0000 [APP/0] OUT at java.lang.Thread.run(Thread.java:745) [na:1.8.0_71-]

PCF SSO auto redirect URI

I created an app and binded the app with PCF SSO. By default redirect URI has the same URL as of application launch URL. when I give a different URL in Auto Redirect URI. I am getting the error.

Invalid redirect https://<samplesso.pcf.com>/login did not match one of the registered values.

This url is my Application launch URL

Invalid redirect http://beth-authcode-sample.cfapps.io/login did not match one of the registered values

I've done the followings and ran into issue

  1. click at app link
  2. presented with index.html
  3. click at the link on index.html
  4. presented with login screen, and entered correct pws user/pass
  5. presented with error page
    a. address bar display = https://btran.login.run.pivotal.io/oauth/authorize?client_id=96a2b234-23ea-49ce-8a3e-ac63c7df3f8f&redirect_uri=http://beth-authcode-sample.cfapps.io/login&response_type=code&state=h8XHaJ
    b. error on page = Invalid redirect http://beth-authcode-sample.cfapps.io/login did not match one of the registered values
  6. the redirect path http://beth-authcode-sample.cfapps.io/login is not in the code

Reading Custom SSO attributes

I requested my LDAP team to give additional user details. After that, I'm struggling to read the additional details from SAML response. What Java class/object would require

Environment variables do not bootstrap correctly in the SSO tile

I'm trying to follow the sample app for client_credential grant_type. I cannot figure out which environment variable corresponds with the scopes listed for the application within the SSO tile's management screen.

For example, if I have a scope of foo.app.writer and I want to bootstrap my app with the manifest and use this scope, I was expecting to have something like:

SSO_AUTHORITIES: uaa.resource, foo.app.writer

The only scope that shows up is uaa.resource

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.