-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3745 from MDeLuise/feature/user-profile-info
Add the possibility for an authenticated user to read and change his own profile information
- Loading branch information
Showing
21 changed files
with
688 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
qa/common/src/main/java/org/eclipse/kapua/qa/common/cucumber/CucUserProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.qa.common.cucumber; | ||
|
||
public class CucUserProfile { | ||
private String displayName; | ||
private String phoneNumber; | ||
private String email; | ||
|
||
|
||
public CucUserProfile(String displayName, String phoneNumber, String email) { | ||
this.displayName = displayName; | ||
this.phoneNumber = phoneNumber; | ||
this.email = email; | ||
} | ||
|
||
|
||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
|
||
public void setDisplayName(String displayName) { | ||
this.displayName = displayName; | ||
} | ||
|
||
|
||
public String getPhoneNumber() { | ||
return phoneNumber; | ||
} | ||
|
||
|
||
public void setPhoneNumber(String phoneNumber) { | ||
this.phoneNumber = phoneNumber; | ||
} | ||
|
||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ion/src/test/java/org/eclipse/kapua/integration/service/user/RunUserProfileUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.integration.service.user; | ||
|
||
import io.cucumber.junit.Cucumber; | ||
import io.cucumber.junit.CucumberOptions; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Cucumber.class) | ||
@CucumberOptions( | ||
features = { "classpath:features/user/UserProfileUnitTests.feature" | ||
}, | ||
glue = {"org.eclipse.kapua.service.security.test", | ||
"org.eclipse.kapua.service.authorization.steps", | ||
"org.eclipse.kapua.service.authentication.steps", | ||
"org.eclipse.kapua.service.user.steps", | ||
"org.eclipse.kapua.service.account.steps", | ||
"org.eclipse.kapua.qa.common" | ||
}, | ||
plugin = {"pretty", | ||
"html:target/cucumber/UserProfile", | ||
"json:target/UserProfile_cucumber.json" | ||
}, | ||
monochrome = true) | ||
public class RunUserProfileUnitTests { | ||
} |
62 changes: 62 additions & 0 deletions
62
qa/integration/src/test/resources/features/user/UserProfileUnitTests.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
############################################################################### | ||
# Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others | ||
# | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Eurotech | ||
############################################################################### | ||
@security | ||
@env_none | ||
|
||
Feature: User Credential | ||
This feature file contains Unit tests for User Profile. | ||
|
||
@setup | ||
Scenario: Initialize test environment | ||
Given Init Jaxb Context | ||
And Init Security Context | ||
|
||
Scenario: Change User Profile correctly | ||
Create a user, login with it, change the user profile and then check if the operation is performed correctly. | ||
Given I login as user with name "kapua-sys" and password "kapua-password" | ||
And I change the profile to the following | ||
| displayName | phoneNumber | email | | ||
| Foo | 424242 | foo@bar.com | | ||
When I search for user with name "kapua-sys" | ||
Then I find user | ||
| kapua-sys | Foo | foo@bar.com | 424242 | ENABLED | | ||
And I logout | ||
|
||
Scenario: Change User Profile correctly to all blank values | ||
Create a user, login with it, change the user profile with all fields blank, and then check if the operation is performed correctly. | ||
Given I login as user with name "kapua-sys" and password "kapua-password" | ||
And I change the profile to the following | ||
| displayName | phoneNumber | email | | ||
| | | | | ||
When I search for user with name "kapua-sys" | ||
Then I find user | ||
| kapua-sys | | | | ENABLED | | ||
And I logout | ||
|
||
Scenario: Change User Profile incorrectly | ||
Create a user, login with it, change the user profile incorrectly, and then check if the exception is occurred. | ||
Given I login as user with name "kapua-sys" and password "kapua-password" | ||
And I expect the exception "KapuaIllegalArgumentException" with the text "An illegal value was provided for the argument userProfile.email: foo.com." | ||
When I change the profile to the following | ||
| displayName | phoneNumber | email | | ||
| Foo | 424242 | foo.com | | ||
Then An exception was thrown | ||
And I logout | ||
|
||
Scenario: Read User Profile correctly | ||
Create a user, login with it, and then read its user profile. | ||
Given I login as user with name "kapua-sys" and password "kapua-password" | ||
Then I read the following user profile | ||
| displayName | phoneNumber | email | | ||
| Kapua Sysadmin | +1 555 123 4567 | kapua-sys@eclipse.org | | ||
And I logout |
51 changes: 51 additions & 0 deletions
51
...esources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/UserProfiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.app.api.resources.v1.resources; | ||
|
||
import org.eclipse.kapua.KapuaException; | ||
import org.eclipse.kapua.app.api.core.model.ScopeId; | ||
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource; | ||
import org.eclipse.kapua.locator.KapuaLocator; | ||
import org.eclipse.kapua.service.user.profile.UserProfile; | ||
import org.eclipse.kapua.service.user.profile.UserProfileService; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("{scopeId}/user/profile") | ||
public class UserProfiles extends AbstractKapuaResource { | ||
private final KapuaLocator locator = KapuaLocator.getInstance(); | ||
private final UserProfileService userProfileService = locator.getService(UserProfileService.class); | ||
|
||
|
||
@PUT | ||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
public Response changeUserProfile(@PathParam("scopeId") ScopeId scopeId, UserProfile userProfile) throws KapuaException { | ||
userProfileService.changeUserProfile(userProfile); | ||
return returnOk(); | ||
} | ||
|
||
@GET | ||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
public UserProfile getUserProfile(@PathParam("scopeId") ScopeId scopeId) throws KapuaException { | ||
return userProfileService.getUserProfile(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
rest-api/resources/src/main/resources/openapi/userProfile/userProfile-scopeId.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
openapi: 3.0.2 | ||
|
||
info: | ||
title: Everyware Cloud REST API - User Profile | ||
version: '1.0' | ||
contact: | ||
name: Eurotech | ||
url: https://www.eurotech.com | ||
|
||
paths: | ||
|
||
/{scopeId}/user/profile/: | ||
get: | ||
tags: | ||
- User Profile | ||
summary: Get the User Profile | ||
operationId: userProfileGet | ||
parameters: | ||
- $ref: '../openapi.yaml#/components/parameters/scopeId' | ||
responses: | ||
200: | ||
description: The desired user profile | ||
content: | ||
application/json: | ||
schema: | ||
$ref: './userProfile.yaml#/components/schemas/userProfile' | ||
401: | ||
$ref: '../openapi.yaml#/components/responses/unauthenticated' | ||
403: | ||
$ref: '../openapi.yaml#/components/responses/subjectUnauthorized' | ||
404: | ||
$ref: '../openapi.yaml#/components/responses/entityNotFound' | ||
500: | ||
$ref: '../openapi.yaml#/components/responses/kapuaError' | ||
put: | ||
tags: | ||
- User Profile | ||
summary: Change the User Profile | ||
operationId: userProfileUpdate | ||
parameters: | ||
- $ref: '../openapi.yaml#/components/parameters/scopeId' | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../openapi.yaml#/components/schemas/userProfile' | ||
responses: | ||
200: | ||
description: The user profile has been updated | ||
401: | ||
$ref: '../openapi.yaml#/components/responses/unauthenticated' | ||
403: | ||
$ref: '../openapi.yaml#/components/responses/subjectUnauthorized' | ||
500: | ||
$ref: '../openapi.yaml#/components/responses/kapuaError' | ||
description: Change logged user profile |
28 changes: 28 additions & 0 deletions
28
rest-api/resources/src/main/resources/openapi/userProfile/userProfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
openapi: 3.0.2 | ||
|
||
info: | ||
title: Everyware Cloud REST API - User Profile | ||
version: '1.0' | ||
contact: | ||
name: Eurotech | ||
url: https://www.eurotech.com | ||
|
||
paths: {} | ||
|
||
components: | ||
schemas: | ||
userProfile: | ||
allOf: | ||
- description: The user profile | ||
type: object | ||
properties: | ||
displayName: | ||
type: string | ||
phoneNumber: | ||
type: string | ||
email: | ||
type: string | ||
example: | ||
displayName: "Foo42" | ||
phoneNumber: "424202424" | ||
email: "foo@bar.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.