-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
43 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
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
17 changes: 17 additions & 0 deletions
17
openmetadata-service/src/main/resources/json/data/role/DefaultBotRole.json
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,17 @@ | ||
{ | ||
"name": "DefaultBotRole", | ||
"displayName": "Default Bot Role", | ||
"description": "Role Corresponding to a Bot by default.", | ||
"allowDelete": false, | ||
"provider": "system", | ||
"policies" : [ | ||
{ | ||
"type" : "policy", | ||
"name" : "DefaultBotPolicy" | ||
}, | ||
{ | ||
"type" : "policy", | ||
"name" : "DataConsumerPolicy" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,8 @@ | |
import static org.openmetadata.service.exception.CatalogExceptionMessage.notAdmin; | ||
import static org.openmetadata.service.exception.CatalogExceptionMessage.operationNotAllowed; | ||
import static org.openmetadata.service.exception.CatalogExceptionMessage.permissionNotAllowed; | ||
import static org.openmetadata.service.jdbi3.RoleRepository.DEFAULT_BOT_ROLE; | ||
import static org.openmetadata.service.jdbi3.RoleRepository.DOMAIN_ONLY_ACCESS_ROLE; | ||
import static org.openmetadata.service.resources.teams.UserResource.USER_PROTECTED_FIELDS; | ||
import static org.openmetadata.service.security.SecurityUtil.authHeaders; | ||
import static org.openmetadata.service.util.EntityUtil.fieldAdded; | ||
|
@@ -109,18 +111,17 @@ | |
import org.openmetadata.schema.auth.RegistrationRequest; | ||
import org.openmetadata.schema.auth.RevokePersonalTokenRequest; | ||
import org.openmetadata.schema.auth.RevokeTokenRequest; | ||
import org.openmetadata.schema.auth.SSOAuthMechanism; | ||
import org.openmetadata.schema.entity.data.Table; | ||
import org.openmetadata.schema.entity.teams.AuthenticationMechanism; | ||
import org.openmetadata.schema.entity.teams.AuthenticationMechanism.AuthType; | ||
import org.openmetadata.schema.entity.teams.Role; | ||
import org.openmetadata.schema.entity.teams.Team; | ||
import org.openmetadata.schema.entity.teams.User; | ||
import org.openmetadata.schema.security.client.GoogleSSOClientConfig; | ||
import org.openmetadata.schema.type.ApiStatus; | ||
import org.openmetadata.schema.type.ChangeDescription; | ||
import org.openmetadata.schema.type.EntityReference; | ||
import org.openmetadata.schema.type.ImageList; | ||
import org.openmetadata.schema.type.Include; | ||
import org.openmetadata.schema.type.MetadataOperation; | ||
import org.openmetadata.schema.type.Profile; | ||
import org.openmetadata.schema.type.Webhook; | ||
|
@@ -129,6 +130,7 @@ | |
import org.openmetadata.service.Entity; | ||
import org.openmetadata.service.auth.JwtResponse; | ||
import org.openmetadata.service.exception.CatalogExceptionMessage; | ||
import org.openmetadata.service.jdbi3.RoleRepository; | ||
import org.openmetadata.service.jdbi3.TeamRepository.TeamCsv; | ||
import org.openmetadata.service.jdbi3.UserRepository.UserCsv; | ||
import org.openmetadata.service.resources.EntityResourceTest; | ||
|
@@ -150,11 +152,13 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> { | |
private static final Profile PROFILE = | ||
new Profile().withImages(new ImageList().withImage(URI.create("https://image.com"))); | ||
private static final TeamResourceTest TEAM_TEST = new TeamResourceTest(); | ||
private final RoleRepository roleRepository; | ||
|
||
public UserResourceTest() { | ||
super(USER, User.class, UserList.class, "users", UserResource.FIELDS); | ||
supportedNameCharacters = "_-."; | ||
supportsSearchIndex = true; | ||
roleRepository = Entity.getRoleRepository(); | ||
} | ||
|
||
public void setupUsers(TestInfo test) throws HttpResponseException { | ||
|
@@ -193,6 +197,11 @@ public void setupUsers(TestInfo test) throws HttpResponseException { | |
Set<String> userFields = Entity.getEntityFields(User.class); | ||
userFields.remove("authenticationMechanism"); | ||
BOT_USER = getEntityByName(INGESTION_BOT, String.join(",", userFields), ADMIN_AUTH_HEADERS); | ||
|
||
// Get the bot roles | ||
DEFAULT_BOT_ROLE_REF = roleRepository.getReferenceByName(DEFAULT_BOT_ROLE, Include.NON_DELETED); | ||
DOMAIN_ONLY_ACCESS_ROLE_REF = | ||
roleRepository.getReferenceByName(DOMAIN_ONLY_ACCESS_ROLE, Include.NON_DELETED); | ||
} | ||
|
||
@Test | ||
|
@@ -886,28 +895,26 @@ protected void validateCommonEntityFields(User entity, CreateEntity create, Stri | |
void put_generateToken_bot_user_200_ok() throws HttpResponseException { | ||
AuthenticationMechanism authMechanism = | ||
new AuthenticationMechanism() | ||
.withAuthType(AuthType.SSO) | ||
.withConfig( | ||
new SSOAuthMechanism() | ||
.withSsoServiceType(SSOAuthMechanism.SsoServiceType.GOOGLE) | ||
.withAuthConfig( | ||
new GoogleSSOClientConfig().withSecretKey("/path/to/secret.json"))); | ||
.withAuthType(AuthType.JWT) | ||
.withConfig(new JWTAuthMechanism().withJWTTokenExpiry(JWTTokenExpiry.Unlimited)); | ||
CreateUser create = | ||
createBotUserRequest("ingestion-bot-jwt") | ||
.withEmail("[email protected]") | ||
.withRoles(List.of(ROLE1_REF.getId())) | ||
.withAuthenticationMechanism(authMechanism); | ||
User user = createEntity(create, USER_WITH_CREATE_HEADERS); | ||
user = getEntity(user.getId(), "*", ADMIN_AUTH_HEADERS); | ||
assertEquals(1, user.getRoles().size()); | ||
// Has the given role and the default bot role | ||
assertEquals(2, user.getRoles().size()); | ||
TestUtils.put( | ||
getResource(String.format("users/generateToken/%s", user.getId())), | ||
new GenerateTokenRequest().withJWTTokenExpiry(JWTTokenExpiry.Seven), | ||
OK, | ||
ADMIN_AUTH_HEADERS); | ||
user = getEntity(user.getId(), "*", ADMIN_AUTH_HEADERS); | ||
assertNull(user.getAuthenticationMechanism()); | ||
assertEquals(1, user.getRoles().size()); | ||
// Has the given role and the default bot role | ||
assertEquals(2, user.getRoles().size()); | ||
JWTAuthMechanism jwtAuthMechanism = | ||
TestUtils.get( | ||
getResource(String.format("users/token/%s", user.getId())), | ||
|
@@ -1441,6 +1448,14 @@ public void validateCreatedEntity( | |
for (UUID roleId : listOrEmpty(createRequest.getRoles())) { | ||
expectedRoles.add(new EntityReference().withId(roleId).withType(Entity.ROLE)); | ||
} | ||
|
||
// bots are created with default roles | ||
if (createRequest.getIsBot()) { | ||
expectedRoles.add(DEFAULT_BOT_ROLE_REF); | ||
if (!nullOrEmpty(createRequest.getDomains())) { | ||
expectedRoles.add(DOMAIN_ONLY_ACCESS_ROLE_REF); | ||
} | ||
} | ||
assertRoles(user, expectedRoles); | ||
|
||
List<EntityReference> expectedTeams = new ArrayList<>(); | ||
|