Skip to content

Commit a8a2e76

Browse files
committed
Show the tenant group in the dqops cloud calls.
1 parent 931a27c commit a8a2e76

File tree

7 files changed

+46
-27
lines changed

7 files changed

+46
-27
lines changed

dqops/src/main/java/com/dqops/core/dqocloud/accesskey/DqoCloudCredentialsProviderImpl.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,46 @@ public DqoCloudCredentialsProviderImpl(DqoCloudApiClientFactory dqoCloudApiClien
5555
public TenantAccessTokenModel issueTenantAccessToken(DqoRoot rootType, UserDomainIdentity userIdentity) {
5656
ApiClient authenticatedClient = this.dqoCloudApiClientFactory.createAuthenticatedClient(userIdentity);
5757
AccessTokenIssueApi accessTokenIssueApi = new AccessTokenIssueApi(authenticatedClient);
58+
String tenantIdFull = userIdentity.getTenantId() + "/" + userIdentity.getTenantGroupId();
5859
switch (rootType) {
5960
case data_sensor_readouts:
60-
return accessTokenIssueApi.issueBucketSensorReadoutsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
61+
return accessTokenIssueApi.issueBucketSensorReadoutsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
6162

6263
case data_check_results:
63-
return accessTokenIssueApi.issueBucketCheckResultsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
64+
return accessTokenIssueApi.issueBucketCheckResultsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
6465

6566
case data_errors:
66-
return accessTokenIssueApi.issueBucketErrorsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
67+
return accessTokenIssueApi.issueBucketErrorsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
6768

6869
case data_statistics:
69-
return accessTokenIssueApi.issueBucketStatisticsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
70+
return accessTokenIssueApi.issueBucketStatisticsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
7071

7172
case data_incidents:
72-
return accessTokenIssueApi.issueBucketIncidentsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
73+
return accessTokenIssueApi.issueBucketIncidentsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
7374

7475
case sources:
75-
return accessTokenIssueApi.issueBucketSourcesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
76+
return accessTokenIssueApi.issueBucketSourcesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
7677

7778
case sensors:
78-
return accessTokenIssueApi.issueBucketSensorsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
79+
return accessTokenIssueApi.issueBucketSensorsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
7980

8081
case rules:
81-
return accessTokenIssueApi.issueBucketRulesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
82+
return accessTokenIssueApi.issueBucketRulesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
8283

8384
case checks:
84-
return accessTokenIssueApi.issueBucketChecksRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
85+
return accessTokenIssueApi.issueBucketChecksRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
8586

8687
case settings:
87-
return accessTokenIssueApi.issueBucketSettingsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
88+
return accessTokenIssueApi.issueBucketSettingsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
8889

8990
case credentials:
90-
return accessTokenIssueApi.issueBucketCredentialsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
91+
return accessTokenIssueApi.issueBucketCredentialsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
9192

9293
case dictionaries:
93-
return accessTokenIssueApi.issueBucketDictionariesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
94+
return accessTokenIssueApi.issueBucketDictionariesRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
9495

9596
case patterns:
96-
return accessTokenIssueApi.issueBucketPatternsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), userIdentity.getTenantId());
97+
return accessTokenIssueApi.issueBucketPatternsRWAccessToken(userIdentity.getDataDomainCloud(), userIdentity.getTenantOwner(), tenantIdFull);
9798

9899
default:
99100
throw new RuntimeException("Unknown root: " + rootType);

dqops/src/main/java/com/dqops/core/principal/DqoUserPrincipal.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class DqoUserPrincipal {
4444
public DqoUserPrincipal(String dataDomainFolder, String dataDomainCloud) {
4545
this.accountRole = DqoUserRole.NONE;
4646
this.privileges = Collections.unmodifiableList(new ArrayList<>());
47-
this.dataDomainIdentity = new UserDomainIdentity(UNAUTHENTICATED_PRINCIPAL_NAME, DqoUserRole.NONE, dataDomainFolder, dataDomainCloud, null, null);
47+
this.dataDomainIdentity = new UserDomainIdentity(UNAUTHENTICATED_PRINCIPAL_NAME, DqoUserRole.NONE, dataDomainFolder, dataDomainCloud, null, null, null);
4848
}
4949

5050
/**
@@ -56,17 +56,19 @@ public DqoUserPrincipal(String dataDomainFolder, String dataDomainCloud) {
5656
* @param dataDomainCloud The real data domain on DQOps cloud that is mounted.
5757
* @param tenantOwner Tenant owner's email.
5858
* @param tenantId Tenant id.
59+
* @param tenantGroupId Tenant group id.
5960
*/
6061
public DqoUserPrincipal(String name,
6162
DqoUserRole accountRole,
6263
Collection<GrantedAuthority> privileges,
6364
String dataDomainFolder,
6465
String dataDomainCloud,
6566
String tenantOwner,
66-
String tenantId) {
67+
String tenantId,
68+
Integer tenantGroupId) {
6769
this.accountRole = accountRole;
6870
this.privileges = privileges;
69-
this.dataDomainIdentity = new UserDomainIdentity(name, accountRole, dataDomainFolder, dataDomainCloud, tenantOwner, tenantId);
71+
this.dataDomainIdentity = new UserDomainIdentity(name, accountRole, dataDomainFolder, dataDomainCloud, tenantOwner, tenantId, tenantGroupId);
7072
}
7173

7274
/**
@@ -82,7 +84,8 @@ public DqoUserPrincipal(String name, DqoUserRole accountRole, Collection<Granted
8284
DqoCloudApiKeyPayload apiKeyPayload, String dataDomainFolder, String dataDomainCloud) {
8385
this(name, accountRole, privileges, dataDomainFolder, dataDomainCloud,
8486
apiKeyPayload != null ? apiKeyPayload.getSubject() : null,
85-
apiKeyPayload != null ? apiKeyPayload.getTenantId() : null);
87+
apiKeyPayload != null ? apiKeyPayload.getTenantId() : null,
88+
apiKeyPayload != null ? apiKeyPayload.getTenantGroup() : null);
8689
this.apiKeyPayload = apiKeyPayload;
8790
}
8891

@@ -95,10 +98,11 @@ public DqoUserPrincipal(String name, DqoUserRole accountRole, Collection<Granted
9598
* @param dataDomainFolder The data domain folder name.
9699
* @param dataDomainCloud The real data domain on DQOps cloud that is mounted.
97100
* @param tenantId Tenant id.
101+
* @param tenantGroupId Tenant group id.
98102
*/
99103
public DqoUserPrincipal(String name, DqoUserRole accountRole, Collection<GrantedAuthority> privileges, DqoUserTokenPayload userTokenPayload,
100-
String dataDomainFolder, String dataDomainCloud, String tenantId) {
101-
this(name, accountRole, privileges, dataDomainFolder, dataDomainCloud, name, tenantId);
104+
String dataDomainFolder, String dataDomainCloud, String tenantId, Integer tenantGroupId) {
105+
this(name, accountRole, privileges, dataDomainFolder, dataDomainCloud, name, tenantId, tenantGroupId);
102106
this.userTokenPayload = userTokenPayload;
103107
}
104108

dqops/src/main/java/com/dqops/core/principal/DqoUserPrincipalProviderImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public DqoUserPrincipal createUserPrincipalForAdministrator() {
7979
// user not authenticated to DQOps Cloud, so we use a default token
8080
List<GrantedAuthority> adminPrivileges = DqoPermissionGrantedAuthorities.getPrivilegesForRole(DqoUserRole.ADMIN);
8181
DqoUserPrincipal dqoUserPrincipalLocal = new DqoUserPrincipal("", DqoUserRole.ADMIN, adminPrivileges,
82-
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null);
82+
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null, null);
8383
return dqoUserPrincipalLocal;
8484
}
8585

@@ -104,7 +104,7 @@ public DqoUserPrincipal getLocalUserPrincipal() {
104104
// user not authenticated to DQOps Cloud, so we use a default token
105105
List<GrantedAuthority> adminPrivileges = DqoPermissionGrantedAuthorities.getPrivilegesForRole(DqoUserRole.ADMIN);
106106
DqoUserPrincipal dqoUserPrincipalLocal = new DqoUserPrincipal("", DqoUserRole.ADMIN, adminPrivileges,
107-
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null);
107+
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null, null);
108108
return dqoUserPrincipalLocal;
109109
}
110110

dqops/src/main/java/com/dqops/core/principal/UserDomainIdentity.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ public class UserDomainIdentity {
4444
/**
4545
* The default identity of the local instance, a user who manages the root data domain on this DQOps instance.
4646
*/
47-
public static final UserDomainIdentity LOCAL_INSTANCE_ADMIN_IDENTITY = new UserDomainIdentity(SYSTEM_USER, DqoUserRole.ADMIN, DEFAULT_DATA_DOMAIN, DEFAULT_DATA_DOMAIN, null, null);
47+
public static final UserDomainIdentity LOCAL_INSTANCE_ADMIN_IDENTITY = new UserDomainIdentity(SYSTEM_USER, DqoUserRole.ADMIN, DEFAULT_DATA_DOMAIN,
48+
DEFAULT_DATA_DOMAIN, null, null, null);
4849

4950
private final String userName;
5051
private final DqoUserRole domainRole;
5152
private final String dataDomainFolder;
5253
private final String dataDomainCloud;
5354
private final String tenantOwner;
5455
private final String tenantId;
56+
private final Integer tenantGroupId;
5557

5658
/**
5759
* Creates a user identity object.
@@ -61,19 +63,22 @@ public class UserDomainIdentity {
6163
* @param dataDomainCloud The real data domain on DQOps cloud that is mounted.
6264
* @param tenantOwner The email of the tenant owner.
6365
* @param tenantId The tenant id.
66+
* @param tenantGroupId Tenant group id.
6467
*/
6568
public UserDomainIdentity(String userName,
6669
DqoUserRole domainRole,
6770
String dataDomainFolder,
6871
String dataDomainCloud,
6972
String tenantOwner,
70-
String tenantId) {
73+
String tenantId,
74+
Integer tenantGroupId) {
7175
this.userName = userName;
7276
this.domainRole = domainRole;
7377
this.dataDomainFolder = !Strings.isNullOrEmpty(dataDomainFolder) ? dataDomainFolder : DEFAULT_DATA_DOMAIN;
7478
this.dataDomainCloud = dataDomainCloud;
7579
this.tenantOwner = tenantOwner;
7680
this.tenantId = tenantId;
81+
this.tenantGroupId = tenantGroupId;
7782
}
7883

7984
/**
@@ -83,7 +88,7 @@ public UserDomainIdentity(String userName,
8388
* @return System user identity for the given data domain.
8489
*/
8590
public static UserDomainIdentity createDataDomainAdminIdentity(String dataDomainFolder, String dataDomainCloud) {
86-
return new UserDomainIdentity(SYSTEM_USER, DqoUserRole.ADMIN, dataDomainFolder, dataDomainCloud, null, null);
91+
return new UserDomainIdentity(SYSTEM_USER, DqoUserRole.ADMIN, dataDomainFolder, dataDomainCloud, null, null, null);
8792
}
8893

8994
/**
@@ -135,6 +140,14 @@ public String getTenantId() {
135140
return tenantId;
136141
}
137142

143+
/**
144+
* Returns the tenant group id.
145+
* @return Tenant group id.
146+
*/
147+
public Integer getTenantGroupId() {
148+
return tenantGroupId;
149+
}
150+
138151
@Override
139152
public boolean equals(Object o) {
140153
if (this == o) return true;

dqops/src/main/java/com/dqops/rest/server/authentication/DqoAuthenticationTokenFactoryImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Authentication createAuthenticatedWithUserToken(DqoUserTokenPayload userT
9898

9999
List<GrantedAuthority> grantedPrivileges = DqoPermissionGrantedAuthorities.getPrivilegesForRole(effectiveRole);
100100
DqoUserPrincipal dqoUserPrincipal = new DqoUserPrincipal(userTokenPayload.getUser(), userTokenPayload.getAccountRole(),
101-
grantedPrivileges, userTokenPayload, dataDomainFolderName, effectiveCloudDataDomainName, userTokenPayload.getTenantId());
101+
grantedPrivileges, userTokenPayload, dataDomainFolderName, effectiveCloudDataDomainName, userTokenPayload.getTenantId(), userTokenPayload.getTenantGroup());
102102

103103
UsernamePasswordAuthenticationToken apiKeyAuthenticationToken = new UsernamePasswordAuthenticationToken(
104104
dqoUserPrincipal, userTokenPayload, dqoUserPrincipal.getPrivileges());

dqops/src/test/java/com/dqops/core/principal/DqoUserPrincipalObjectMother.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class DqoUserPrincipalObjectMother {
3232
public static DqoUserPrincipal createStandaloneAdmin() {
3333
List<GrantedAuthority> privileges = DqoPermissionGrantedAuthorities.getPrivilegesForRole(DqoUserRole.ADMIN);
3434
DqoUserPrincipal dqoUserPrincipal = new DqoUserPrincipal("test", DqoUserRole.ADMIN, privileges,
35-
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null);
35+
UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null, null);
3636
return dqoUserPrincipal;
3737
}
3838
}

dqops/src/test/java/com/dqops/core/principal/UserDomainIdentityObjectMother.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class UserDomainIdentityObjectMother {
2727
* @return Admin user identity.
2828
*/
2929
public static UserDomainIdentity createAdminIdentity() {
30-
return new UserDomainIdentity("test", DqoUserRole.ADMIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null);
30+
return new UserDomainIdentity("test", DqoUserRole.ADMIN, UserDomainIdentity.DEFAULT_DATA_DOMAIN,
31+
UserDomainIdentity.DEFAULT_DATA_DOMAIN, null, null, null);
3132
}
3233
}

0 commit comments

Comments
 (0)