Skip to content

Latest commit

 

History

History
297 lines (179 loc) · 18.1 KB

sap-xsuaa-connector.md

File metadata and controls

297 lines (179 loc) · 18.1 KB
title linktitle url category weight description tags aliases
XSUAA Connector for SAP Business Technology Platform
XSUAA Connector for SAP BTP
/appstore/modules/sap/sap-xsuaa-connector/
SAP
40
Presents reference information on the XSUAA Connector for SAP Business Technology Platform.
SAP
SSO
XSUAA
SAP BTP
SAP Business Technology Platform
/partners/sap/sap-xsuaa-connector/
/partners/sap/use-sap-xsuaa-connector/
/appstore/connectors/sap/sap-xsuaa-connector/

1 Introduction

XSUAA is a service provided by the SAP Business Technology Platform (SAP BTP) that will bind to the Mendix application as soon as the application is deployed within the SAP Business Technology Platform (SAP BTP) using the deployment features in the Mendix Developer Portal.

Out of the box, SAP BTP has the SAP external identify provider (IDP) configured as the default IDP. It is possible to use your own (corporate) IDP as an alternative so that you can automatically give access to all the employees of your organization.

1.1 Typical Use Cases

When you deploy an application to SAP Business Technology Platform (SAP BTP) using the SAP deployment features of the Mendix Developer Portal, it is bound automatically to the XSUAA service. This service allows you to use an external identity provider (IdP) for a Mendix application. In this way, instead of having their user credentials stored separately in the Mendix app, the user can sign on to their app using the IdP and thus have a single sign-on (SSO) experience with their application.

In this diagram, the relationship is shown between groups, roles, and users in relation to the Mendix application and the IdP:

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/xsuaa-diagram.png" class="no-border" >}}

A Mendix application is role-based by default. When deploying a Mendix app to SAP BTP using the deployment features in the Mendix Developer Portal, the SAP BTP application configuration is automatically created (identified in the yellow section of the diagram above). This configuration reflects the roles that are defined in the Mendix app (identified in the blue section of the diagram).

To assign users from the IDP to these roles generated by the model, the account admin needs to add the mapping between the IDP user groups and the role templates (identified in the orange section of the diagram).

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/trusted-idp.png" class="no-border" >}}

1.2 Prerequisites

Before starting this how-to, make sure you have completed the following prerequisites:

  • Create an SAP app using an SAP app template

  • Select and deploy the app to an SAP account and subaccount where you have authority to configure security

  • Set the security level for the app to at least Prototype/demo to use SAP Authentication; for more information see App Security and for instructions on setting security levels, see How To Create a Secure App

  • Set up the app with the following two User roles in App > Security: Supervisor and Inspector

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/add-roles-to-app.png" class="no-border" >}}

  • Ensure the app behaves differently according to the user role, so you can see the effect of setting up the roles in XSUAA. For example, give each role a different starting page as described here: Setting Up Navigation

2 Installation

The SAP app may already have the XSUAA Connector for SAP Business Technology Platform installed. If installed, you can find it in the App > Marketplace modules list for the SapAuthentication module.

If the connector is not already in your app, download it from the XSUAA Connector for SAP Business Technology Platform page in the Mendix Marketplace, and then follow the instructions in Using Marketplace Content to import the connector into your app.

3 Configuration

After you install the connector, you can find it in the App > Marketplace modules list, in the SapAuthentication section. Before you can use the connector, you must first perform the necessary configuration steps.

You need to provide your own xs-security.json file to add custom configuration to your XSUAA connector.

  1. Ensure that the xsuaa service is in the status Services To Be Bound. See the Services Tab section of SAP Business Technology Platform for more information.

  2. Click the three dots next to the xsuaa service and select Add Binding Configuration.

You then have two options:

3.1 Use the XSUAA Configurator {#configurator}

The XSUAA Configurator provides a user friendly interface to create the JSON required to configure the XSUAA service. It can be uploaded automatically for you, or you can download the file and upload it manually.

{{% alert color="info" %}} The configurator will only create a JSON file from scratch. It does not have access to your existing XSUAA settings on SAP BTP, and you cannot import an existing JSON files.

You cannot change the xsappname in the configurator – this is generated automatically for your app by the Developer Portal. {{% /alert %}}

  1. Click ⚙️ Configurator to open the configurator.

  2. Set up the configuration in the sections shown on the screen.

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/configurator.png" width="50%" class="no-border" >}}

  3. Click Upload Configuration To Service to upload the configuration automatically. The configuration will be applied when your app is restarted.

    Alternatively, click Download Configuration File to save the file locally so that you can review it, or reuse it. You can upload it manually to the XSUAA service using the instructions in the next section.

3.2 Upload Configuration JSON

You can upload your own JSON configuration file, either created from the XSUAA Configurator or handcrafted.

  1. Click Browse… next to the Configurator JSON option.
  2. Choose the file containing the XSUAA configuration you want to use.

The configuration will be applied when your app is restarted.

4 Usage

When XSUAA is enabled on SAP BTP and the XSUAA Connector for SAP Business Technology Platform is part of the Mendix application, an IDP user automatically becomes a Mendix application user. They will be assigned to the roles in the Mendix application based on the scopes they have received from the XSUAA service. The scopes are defined by the mapping between the role templates and the role collections.

When the IDP user is added to the Mendix application, they are given a randomly generated password to prevent the user being logged in using the local credentials. You can control the length of this randomly-generated password using the SapAuthentication.PasswordLength constant. This can also be set via an environment variable. SapAuthentication.PasswordLength should be at least 8, with a maximum value of 12.

For more information about implementing this capability in your app, see the following sections.

{{% alert color="warning" %}} SAP Authentication will not work if the App Security is off. See the prerequisites above. {{% /alert %}}

4.1 Adding the OnStartup Microflow to the Application Settings

The app needs to be bound to the SAP XSUAA service. This is achieved by executing a microflow when the app starts. This may have been set up already if XSUAA was included in your app template.

To add the After Startup microflow to your application, follow these steps:

  1. In the App Explorer, select App > Settings and open the Runtime tab.
  2. For the After Startup microflow, select the microflow Marketplace modules > SapAuthentication > USE_ME > ASu_StartXSUAA.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/runtime-settings.png" class="no-border" >}}

4.2 Changing the Login Page to Allow XSUAA SSO

By default, the Mendix login page will not allow the user to enter their SSO credentials. There are two ways of changing the login page:

  • Add the SSO login button so the user can choose whether to use SSO or native Mendix credentials
  • Bypass the Mendix login page altogether and just display the XSUAA login page

{{% alert color="info" %}} If you are using the Deep Link module, you will also need to set the LoginLocation constant to /xsauaalogin/login?ret=. {{% /alert %}}

4.2.1 Adding the SSO Login Button to the Login Page {#adding}

{{% alert color="info" %}} If your app already had XSUAA included, your login.html file may have been modified already. {{% /alert %}}

If login.html does not support XSUAA then you need to add the SSO login button to the landing page. Do this by following these steps:

  1. In the top menu of , select App > Show App Directory in Explorer.

  2. Open the theme folder.

  3. Copy the content of login-with-sso.html to login.html.

  4. Open login.html for editing.

  5. Locate the following lines:

    <a id="ssoButton" href="/openid/login" class="btn btn-default btn-lg">
        <img src="logo.png" />
        <span class="loginpage-signin">Mendix Account</span>
    </a>
  6. Replace those lines with the following lines (or add them below the <a> element in the code above):

    <a id="ssoButton" href="/xsauaalogin/" class="btn btn-default btn-lg">
        <img src="logo.png" />
        <span class="loginpage-signin">Sign in using XSUAA</span>
    </a>
  7. Deploy and run your app. The XSUAA login button will look like this:

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/sso-login-screen.png" class="no-border" >}}

4.2.2 Redirecting Your Application to XSUAA Without Showing the Login Page

An alternative to adding the SSO login button to the landing page of your app is to redirect your app to XSUAA automatically without showing the login page.

{{% alert color="info" %}} Note that this will only work if you are running your app on SAP BTP.

Because users will be automatically redirected to XSUAA after signing out of the application, this could cause them to be signed in again. {{% /alert %}}

To accomplish this, follow these steps:

  1. Open the app directory of your app and then open the theme folder.

  2. Change the contents of login.html to the following:

    <!doctype html>
    <html>
        <head>
            <script>
                window.location.assign("/xsauaalogin/")
            </script>
        </head>
    </html>

4.3 Configuring the SAP BTP Subaccount

Your app is configured to use an IdP. Now you need to configure the IdP and allocate users to roles. This is performed in the SAP Business Technology Platform cockpit.

{{% alert color="info" %}} Before configuring the IdP, you must first deploy your app to SAP BTP. This will expose the user roles in the app to the security configuration tools in the SAP BTP cockpit. {{% /alert %}}

{{% alert color="warning" %}} This section describes actions which are carried out using the SAP BTP cockpit. This document uses the current navigation through the SAP BTP cockpit but this is outside the Mendix environment and may be changed. SAP BTP documentation is in the SAP Help Portal. {{% /alert %}}

The diagram below shows the relationship between the security structures in your Mendix app (blue), the SAP BTP app environment (yellow), SAP User Account and Authentication (orange), and the IdP (green).

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/xsuaa-diagram-labeled.png" class="no-border" >}}

Once the user has been authenticated, various attributes (the user's name, for example) are copied from the IdP User (green) to the User entity within the Mendix application (blue) so that they can be used by the app. However the authorization credentials remain in the IdP and the user cannot access the app by using credentials stored in the app.

4.3.1 Scope

When your app is deployed to SAP BTP, each User Role (A) in the Mendix app is exposed as a Scope (B) in the SAP environment. You can see this mapping by going to your app in the SAP BTP cockpit. Under Security you can view the Scopes. You will see that the four User Roles in the Mendix app are exposed as scopes in the application space:

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/app-scopes.png" class="no-border" >}}

4.3.2 Role Template

Each Scope is mapped to a single Role Template (C) during deployment. You can see the Role Templates in the Application details of the SAP BTP cockpit. These are also defined during the deployment of the app.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/app-role-templates.png" class="no-border" >}}

The Attributes of the Role Template are not used by Mendix in linking Mendix Roles to SAP Roles.

4.3.3 Role

In the SAP BTP cockpit, you can view and add additional Roles (D) to the Role Template, or you can stay with the generated default role. Note that new roles added here do not have different roles in your Mendix app. However, adding new roles may allow you to obtain additional analytics through the SAP or IdP logs. Here a new Inspector role (Inspector 2) has been added to the Inspector Role Template.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/app-roles.png" class="no-border" >}}

4.3.4 Role Collection

The Role Collection (E) is defined not for the app deployed to SAP BTP, but in your SAP Subaccount. It is this Role Collection which will be linked to the IdP.

There may be other Role Collections which are being used by other apps deployed in this subaccount and you may, or may not, wish to share authentication between apps. You could, for example, use the same authentication for several related apps running in the same subaccount which have the same app User Roles. Or you may wish to use different authentication for development and production environments.

Here, we add a new Role Collection for the Inspector 2 role in the SAP BTP space roles.

  1. Give the new Role Collection a name and, optionally, a description.

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/new-role-collection.png" class="no-border" >}}

  2. Click on the Name of the Role Collection to allocate roles to the Role Collection.

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/select-role-collection.png" class="no-border" >}}

  3. Add the Role (or Roles) which you want to include in this Role Collection.

    {{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/add-role.png" class="no-border" >}}

The new role collection can now be seen in the SAP BTP cockpit for this Subaccount, with the Role (or Roles) which it includes.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/show-role-collection.png" class="no-border" >}}

4.3.5 Trust Configuration

Your Subaccount will have one or more Trust Configurations. These are the IdPs which you can use to authenticate your users. The default is the SAP ID Service but you may add other IdPs.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/trust-configurations.png" class="no-border" >}}

Depending on the IdP, you can either map Users (G) directly to a Role Collection, or map a User Group (F) to a Role Collection. Users are mapped by the IdPs own configuration to the User Group.

4.3.5.1 Map User Directly to a Role Collection

This is the method used by the SAP ID Service, amongst others.

  1. Click on the SAP ID Service in the Trust Configurations.
  2. Enter the username (email) of an SAP user that you want to give access to.
  3. Click Show Assignments to show existing assignments.
  4. Click Add Assignment and choose the Role Collection (in this case Inspector 2) to which you want to grant access.

The selected user now has access to the selected Role Collection and, through that, to the correct User Role in your app.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/role-collection-assignment-direct.png" class="no-border" >}}

You can picture the authentication as shown below:

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/xsuaa-diagram-config-direct.png" class="no-border" >}}

4.3.5.2 Map User Group to a Role Collection

Some IdPs (for example SAML 2.0 IdPs) have the concept of a User Group. In this case there will be two options in the Trust Configuration for the IdP: Role Collection Mappings and Role Collection Assignment.

You can link an individual username to the Role Collection in the same way as described above using the Role Collection Assignment option.

Alternatively, you can link a Role Collection to an existing Group within the IdP. In this case, you need to do the following.

  1. Open Role Collection Mappings for the IdP.
  2. Create a new Role Collection Mapping and map the Role Collection (for example, Inspector 2 Role Collection) to an existing Group (for example, Inspector 2 Group) in the IdP.

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/role-collection-mapping.png" class="no-border" >}}

Now any user within the IdP which is part of the Inspector 2 Group will have access to the correct role in your Mendix app.

You can picture the authentication as shown below:

{{< figure src="/attachments/appstore/modules/sap-xsuaa-connector/xsuaa-diagram-config-via-group.png" class="no-border" >}}

5 Upgrading the XSUAA Connector

Version 2.1.1 of the XSUAA Connector for SAP Business Technology Platform uses a new user administration module called SapAuthentication. If you are upgrading from version 2.0.0 or below, you will need to migrate your existing users from Administration.Account to SapAuthentication.SapUser using the User Migration Marketplace module.