-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(roles): add ability to invite users into a role (#6015)
- Loading branch information
1 parent
3b1a0c5
commit 325b959
Showing
44 changed files
with
1,563 additions
and
645 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
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
51 changes: 51 additions & 0 deletions
51
...ql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/role/AcceptRoleResolver.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 @@ | ||
package com.linkedin.datahub.graphql.resolvers.role; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.datahub.authentication.invite.InviteTokenService; | ||
import com.datahub.authorization.role.RoleService; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.generated.AcceptRoleInput; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
|
||
@RequiredArgsConstructor | ||
public class AcceptRoleResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
private final RoleService _roleService; | ||
private final InviteTokenService _inviteTokenService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
|
||
final AcceptRoleInput input = bindArgument(environment.getArgument("input"), AcceptRoleInput.class); | ||
final String inviteTokenStr = input.getInviteToken(); | ||
final Authentication authentication = context.getAuthentication(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
Urn inviteTokenUrn = _inviteTokenService.getInviteTokenUrn(inviteTokenStr); | ||
if (!_inviteTokenService.isInviteTokenValid(inviteTokenUrn, authentication)) { | ||
throw new RuntimeException(String.format("Invite token %s is invalid", inviteTokenStr)); | ||
} | ||
|
||
Urn roleUrn = _inviteTokenService.getInviteTokenRole(inviteTokenUrn, authentication); | ||
if (roleUrn != null) { | ||
_roleService.assignRoleToActor(authentication.getActor().toUrnStr(), roleUrn, authentication); | ||
} | ||
|
||
return true; | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to accept role using invite token %s", inviteTokenStr), e); | ||
} | ||
}); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
.../src/main/java/com/linkedin/datahub/graphql/resolvers/role/CreateInviteTokenResolver.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,44 @@ | ||
package com.linkedin.datahub.graphql.resolvers.role; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.datahub.authentication.invite.InviteTokenService; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.CreateInviteTokenInput; | ||
import com.linkedin.datahub.graphql.generated.InviteToken; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.authorization.AuthorizationUtils.*; | ||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class CreateInviteTokenResolver implements DataFetcher<CompletableFuture<InviteToken>> { | ||
private final InviteTokenService _inviteTokenService; | ||
|
||
@Override | ||
public CompletableFuture<InviteToken> get(final DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
if (!canManagePolicies(context)) { | ||
throw new AuthorizationException( | ||
"Unauthorized to create invite tokens. Please contact your DataHub administrator if this needs corrective action."); | ||
} | ||
|
||
final CreateInviteTokenInput input = bindArgument(environment.getArgument("input"), CreateInviteTokenInput.class); | ||
final String roleUrnStr = input.getRoleUrn(); | ||
final Authentication authentication = context.getAuthentication(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
return new InviteToken(_inviteTokenService.getInviteToken(roleUrnStr, true, authentication)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to create invite token for role %s", roleUrnStr), e); | ||
} | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ore/src/main/java/com/linkedin/datahub/graphql/resolvers/role/GetInviteTokenResolver.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,44 @@ | ||
package com.linkedin.datahub.graphql.resolvers.role; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.datahub.authentication.invite.InviteTokenService; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.GetInviteTokenInput; | ||
import com.linkedin.datahub.graphql.generated.InviteToken; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.authorization.AuthorizationUtils.*; | ||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class GetInviteTokenResolver implements DataFetcher<CompletableFuture<InviteToken>> { | ||
private final InviteTokenService _inviteTokenService; | ||
|
||
@Override | ||
public CompletableFuture<InviteToken> get(final DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
if (!canManagePolicies(context)) { | ||
throw new AuthorizationException( | ||
"Unauthorized to get invite tokens. Please contact your DataHub administrator if this needs corrective action."); | ||
} | ||
|
||
final GetInviteTokenInput input = bindArgument(environment.getArgument("input"), GetInviteTokenInput.class); | ||
final String roleUrnStr = input.getRoleUrn(); | ||
final Authentication authentication = context.getAuthentication(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
return new InviteToken(_inviteTokenService.getInviteToken(roleUrnStr, false, authentication)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to get invite token for role %s", roleUrnStr), e); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.