テンプレート処理中にエラーが発生しました。
Java method "com.liferay.portal.json.JSONFactoryImpl.createJSONObject(String)" threw an exception when invoked on com.liferay.portal.json.JSONFactoryImpl object "com.liferay.portal.json.JSONFactoryImpl@2ad66ae2"; see cause exception in the Java stack trace.

----
FTL stack trace ("~" means nesting-related):
	- Failed at: navigationJSONObject = jsonFactoryUti...  [in template "17855804202317#32484267#LEARN-ARTICLE-NAV" at line 4, column 9]
----
1<#assign 
2	groupFriendlyURL = themeDisplay.getScopeGroup().getFriendlyURL() 
3	groupPathFriendlyURLPublic = themeDisplay.getPathFriendlyURLPublic() + groupFriendlyURL 
4	navigationJSONObject = jsonFactoryUtil.createJSONObject(navigation.getData()) 
5	navigationMenuItems = 
6
7			"Analytics Cloud": { 
8				"image": "/documents/d${groupFriendlyURL}/analytics_c-svg", 
9				"title": "Analytics Cloud", 
10				"url": "analytics-cloud" 
11			}, 
12			"Commerce": { 
13				"image": "/documents/d${groupFriendlyURL}/commerce_product-svg", 
14				"title": "Commerce", 
15				"url": "commerce" 
16			}, 
17			"DXP": { 
18				"image": "/documents/d${groupFriendlyURL}/dxp_p-svg", 
19				"title": "DXP / Portal", 
20				"url": "dxp" 
21			}, 
22			"Liferay Cloud": { 
23				"image": "/documents/d${groupFriendlyURL}/dxp_c-svg", 
24				"title": "Liferay Cloud", 
25				"url": "liferay-cloud" 
26			}, 
27			"Reference": { 
28				"image": "/documents/d${groupFriendlyURL}/reference-svg", 
29				"title": "Reference", 
30				"url": "reference" 
31
32
33 
34	breadcrumbJSONArray = navigationJSONObject.getJSONArray("breadcrumb") 
35	childrenJSONArray = navigationJSONObject.getJSONArray("children") 
36	parentJSONObject = navigationJSONObject.getJSONObject("parent") 
37	productJSONObject = breadcrumbJSONArray.getJSONObject(breadcrumbJSONArray.length()-1)!navigationJSONObject.getJSONObject("self") 
38	siblingsJSONArray = navigationJSONObject.getJSONArray("siblings") 
39/> 
40 
41<div class="learn-article-nav"> 
42	<#if productJSONObject?has_content && productJSONObject.getString("title")?has_content && navigationMenuItems[productJSONObject.getString("title")]?has_content && navigationMenuItems[productJSONObject.getString("title")].title?has_content> 
43		<div 
44			class="dropdown learn-article-nav-root learn-dropdown" 
45
46			<div class="learn-article-nav-item"> 
47				<div class="d-flex"> 
48					<div class="learn-article-nav-image"> 
49						<img 
50							class="lexicon-icon lexicon-icon-caret-bottom product-icon" 
51							role="presentation" 
52							src='${navigationMenuItems[productJSONObject.getString("title")].image}' 
53							viewBox="0 0 512 512" 
54						/> 
55					</div> 
56 
57					<span class="learn-article-nav-text">${navigationMenuItems[productJSONObject.getString("title")].title}</span> 
58				</div> 
59 
60				<div id="dropdown-icon"> 
61					<svg 
62						class="lexicon-icon lexicon-icon-caret-bottom" 
63						role="presentation" 
64						viewBox="0 0 512 512" 
65
66						<use xlink:href="/o/admin-theme/images/clay/icons.svg#caret-bottom"></use> 
67					</svg> 
68				</div> 
69			</div> 
70 
71			<ul class="dropdown-menu learn-dropdown-menu"> 
72				<#list navigationMenuItems as key, value> 
73					<li> 
74						<a 
75							class="dropdown-item learn-article-nav-item" 
76							href="/w/${navigationMenuItems[key].url}/index" 
77							tabindex="4" 
78
79							<span class="d-flex"> 
80								<span class="learn-article-nav-image"> 
81									<img 
82										class="lexicon-icon lexicon-icon-caret-bottom product-icon mt-0 mr-2" 
83										role="presentation" 
84										src="${value.image}"height: 25px; margin-left: 5px; max-width: none; width: 25px; 
85										viewBox="0 0 512 512" 
86									/> 
87								</span> 
88								<span class="learn-article-nav-text">${value.title}</span> 
89							</span> 
90 
91							<#if navigationMenuItems[productJSONObject.getString("title")].url == value.url> 
92								<span> 
93									<@clay["icon"] symbol="check" /> 
94								</span> 
95							</#if> 
96						</a> 
97					</li> 
98				</#list> 
99			</ul> 
100		</div> 
101	</#if> 
102 
103	<div class="learn-article-nav-content"> 
104		<#if parentJSONObject?has_content && parentJSONObject.getString("url")?has_content> 
105			<div class="learn-article-nav-item learn-article-nav-parent liferay-nav-item p-2"> 
106				<div class="mr-2"> 
107					<a 
108						href='${parentJSONObject.getString("url")}' 
109
110						<svg 
111							class="lexicon-icon lexicon-icon-angle-left" 
112							role="presentation" 
113							viewBox="0 0 512 512" 
114
115							<use xlink:href="/o/admin-theme/images/clay/icons.svg#angle-left"></use> 
116						</svg> 
117					</a> 
118				</div> 
119 
120				<span>${parentJSONObject.getString("title")}</span> 
121			</div> 
122		</#if> 
123 
124		<#if childrenJSONArray.length() gt 0> 
125			<ul class="m-0 p-2"> 
126				<#list 0..childrenJSONArray.length()-1 as i> 
127					<li class="learn-article-nav-item"> 
128						<a 
129							class='liferay-nav-item ${(navigationJSONObject.getJSONObject("self").url == childrenJSONArray.getJSONObject(i).url)?then("selected", "")}' 
130							href="${childrenJSONArray.getJSONObject(i).url}" 
131
132							<span>${childrenJSONArray.getJSONObject(i).getString("title")}</span> 
133						</a> 
134					</li> 
135				</#list> 
136			</ul> 
137		<#elseif siblingsJSONArray.length() gt 0> 
138			<ul class="m-0 p-2"> 
139				<#list 0..siblingsJSONArray.length()-1 as i> 
140					<li class="learn-article-nav-item"> 
141						<a 
142							class='liferay-nav-item ${(navigationJSONObject.getJSONObject("self").url == siblingsJSONArray.getJSONObject(i).url)?then("selected", "")}' 
143							href="${siblingsJSONArray.getJSONObject(i).url}" 
144
145							<span>${siblingsJSONArray.getJSONObject(i).getString("title")}</span> 
146						</a> 
147					</li> 
148				</#list> 
149			</ul> 
150		</#if> 
151	</div> 
152</div> 

SCIM User API Basics

Liferay DXP 2024.Q1+ Beta Feature

Liferay provides a headless API to perform CRUD operations on SCIM users to keep their identity information in sync with your company’s applications. Use the /scim endpoint from the API Explorer to manage SCIM users.

Adding a User

Start a new Liferay DXP instance by running

docker run -it -m 8g -p 8080:8080

Sign in to Liferay at http://localhost:8080 using the email address test@liferay.com and the password test. When prompted, change the password to learn.

Once Liferay is running,

  1. Download and unzip SCIM User API Basics.

    curl https://resources.learn.liferay.com/dxp/latest/en/installation-and-upgrades/securing-liferay/developer-guide/liferay-g7y9.zip -O
    
    unzip liferay-g7y9.zip
    
  2. Use the cURL script to add a SCIM user in Liferay. On the command line, navigate to the curl folder. Execute the User_POST_ToInstance.sh script.

    ./User_POST_ToInstance.sh
    

    The JSON response shows the addition of a new SCIM user:

    {
       "emails": [
          {
             "type": "default",
             "value": "able@liferay.com",
             "primary": true
          }
       ],
       "meta": {
          "created": "2024-03-13T09:53:22Z",
          "location": "http://localhost:8080/o/scim/v1.0/v2/Users/36433",
          "lastModified": "2024-03-13T09:53:23Z",
          "resourceType": "User"
       },
       "schemas": [
          "urn:ietf:params:scim:schemas:core:2.0:User",
          "urn:ietf:params:scim:schemas:extension:liferay:2.0:User"
       ],
       "urn:ietf:params:scim:schemas:extension:liferay:2.0:User": {
          "birthday": "1970-01-01",
          "male": true
       },
       "name": {
          "familyName": "Baker",
          "givenName": "Able"
       },
       "active": true,
       "externalId": "1446cf10-3de9-6e11-dd15-c561de806259",
       "id": "36433",
       "title": "",
       "userName": "able.baker"
    }
    
  3. Verify this by opening the Global Menu (Applications Menu icon), and navigating to Control PanelUsers and Organizations. See that a new user has been added.

    See that a new user has been added.

  4. Alternatively, call the REST service using the Java client. Navigate into the java folder and compile the source files:

    javac -classpath .:* *.java
    
  5. Run the User_POST_ToInstance class.

    java -classpath .:* User_POST_ToInstance
    

Examine the cURL Command

The User_POST_ToInstance.sh script calls the REST service with a cURL command.

curl \
   "http://localhost:8080/o/scim/v1.0/v2/Users" \
   --data-raw '
      {
         "active": "'true'",
         "emails": [
            {
               "primary": "'true'",
               "type": "default",
               "value": "able@liferay.com"
            }
         ],
         "name": {
            "familyName": "Baker",
            "givenName": "Able"
         },
         "userName": "able.baker"
      }' \
   --header "Content-Type: application/scim+json" \
   --request "POST" \
   --user "test@liferay.com:learn"

Here are the command’s arguments:

ArgumentsDescription
"http://localhost:8080/o/scim/v1.0/v2/Users"The REST service endpoint
--data-raw "{ "active": "'true'", "emails": [ { "primary": "'true'", "type": "default", "value": "able@liferay.com" } ], "name": { "familyName": "Baker", "givenName": "Able" }, "userName": "able.baker" }"The data to post
--header "Content-Type: application/scim+json"Indicates that the request body format is in JSON and conforms to the SCIM protocol.
--request "POST"The HTTP method to invoke at the specified endpoint
--user "test@liferay.com:learn"Basic authentication credentials
Note

Basic authentication is used here for demonstration purposes. For production, you should authorize users via OAuth2. See Using OAuth2 to Authorize Users for a sample React application using OAuth2.

Examine the Java Class

The User_POST_ToInstance.java class adds a SCIM user by calling the UserResource service.

public static void main(String[] args) throws Exception {
	UserResource.Builder builder = UserResource.builder();

	UserResource userResource = builder.authentication(
		"test@liferay.com", "learn"
	).build();

	userResource.postV2User(
		new User() {
			{
				active = true;
				name = new Name() {
					{
						familyName = "Baker";
						givenName = "Able";
					}
				};
				emails = new MultiValuedAttribute[] {
					new MultiValuedAttribute() {
						{
							primary = true;
							type = "default";
							value = "able@liferay.com";
						}
					}
				};
				userName = "able.baker";
			}
		});
}

This class invokes the REST service using only three lines of code:

Line (abbreviated)Description
UserResource.Builder builder = ...Get a Builder for generating a UserResource service instance.
UserResource userResource = builder.authentication(...).build();Use basic authentication and generate a UserResource service instance.
userResource.postV2User(...);Call the userResource.postV2User method.

Note that the project includes the com.liferay.scim.rest.client.jar file as a dependency. You can find client JAR dependency information for all REST applications in the API explorer in your installation at /o/api (e.g., http://localhost:8080/o/api).

Note

The main method’s comment demonstrates running the class.

Important

See UserResource for service details.

Users_GET_FromInstance.sh

Command:

./Users_GET_FromInstance.sh

Code:

curl \
   "http://localhost:8080/o/scim/v1.0/v2/Users" \
   --user "test@liferay.com:learn"

Users_GET_FromInstance.java

Command:

java -classpath .:* Users_GET_FromInstance

Code:

public static void main(String[] args) throws Exception {
	UserResource.Builder builder = UserResource.builder();

	UserResource userResource = builder.authentication(
		"test@liferay.com", "learn"
	).build();

	System.out.println(userResource.getV2Users(null, null));
}

The User objects of your Liferay instance are listed in JSON.

Read API Query Parameters for more information.

Get a User

Get a specific user with the following cURL or Java command. Replace 1234 with the user’s ID.

Tip

Use Users_GET_FromInstance.[java|sh] to get a list of all users, and note the id of the user you want specifically.

User_GET_ById.sh

Command:

./User_GET_ById.sh 1234

Code:

curl \
   "http://localhost:8080/o/scim/v1.0/v2/Users/${1}" \
   --user "test@liferay.com:learn"

User_GET_ById.java

Command:

java -classpath .:* -DuserId=1234 User_GET_ById

Code:

public static void main(String[] args) throws Exception {
	UserResource.Builder builder = UserResource.builder();

	UserResource userResource = builder.authentication(
		"test@liferay.com", "learn"
	).build();

	System.out.println(
		userResource.getV2UserById(
			String.valueOf(System.getProperty("userId"))));
}

The User fields are listed in JSON.

Put a User

Update an existing user with the following cURL and Java commands. Replace 1234 with your user’s ID.

User_PUT_ById.sh

Command:

./User_PUT_ById.sh 1234

Code:

curl \
   "http://localhost:8080/o/scim/v1.0/v2/Users/${1}" \
   --data-raw '
      {
         "emails": [
            {
               "primary": true,
               "type": "default",
               "value": "able@liferay.com"
            }
         ],
         "name": {
            "familyName": "Charlie",
            "givenName": "Able"
         },
         "userName": "able.baker"
      }' \
   --header "Content-Type: application/scim+json" \
   --request "PUT" \
   --user "test@liferay.com:learn"

User_PUT_ById.java

Command:

java -classpath .:* -DuserId=1234 User_PUT_ById

Code:

public static void main(String[] args) throws Exception {
	UserResource.Builder builder = UserResource.builder();

	UserResource userResource = builder.authentication(
		"test@liferay.com", "learn"
	).build();

	userResource.putV2User(
		String.valueOf(System.getProperty("userId")),
		new User() {
			{
				name = new Name() {
					{
						familyName = "Charlie";
						givenName = "Able";
					}
				};
				emails = new MultiValuedAttribute[] {
					new MultiValuedAttribute() {
						{
							primary = true;
							type = "default";
							value = "able@liferay.com";
						}
					}
				};
				userName = "able.baker";
			}
		});
}

Deactivate a User

Deactivate an existing user with the following cURL and Java commands. Replace 1234 with your user’s ID.

User_DELETE_ById.sh

Command:

./User_DELETE_ById.sh 1234

Code:

curl \
   "http://localhost:8080/o/scim/v1.0/v2/Users/${1}" \
   --request "DELETE" \
   --user "test@liferay.com:learn"

User_DELETE_ById.java

Command

java -classpath .:* -DuserId=1234 User_DELETE_ById

Code:

public static void main(String[] args) throws Exception {
	UserResource.Builder builder = UserResource.builder();

	UserResource userResource = builder.authentication(
		"test@liferay.com", "learn"
	).build();

	userResource.deleteV2User(String.valueOf(System.getProperty("userId")));
}

The API Explorer lists all of the User services and schemas and has an interface to try out each service.