-
Notifications
You must be signed in to change notification settings - Fork 5
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
43 changed files
with
322 additions
and
515 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
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
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
94 changes: 45 additions & 49 deletions
94
...rc/main/java/bio/terra/pearl/api/admin/service/auth/EnforcePortalEnvPermissionAspect.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 |
---|---|---|
@@ -1,61 +1,57 @@ | ||
package bio.terra.pearl.api.admin.service.auth; | ||
|
||
import bio.terra.pearl.api.admin.service.auth.context.PortalEnvAuthContext; | ||
import bio.terra.pearl.api.admin.service.auth.context.PortalStudyEnvAuthContext; | ||
import bio.terra.pearl.core.model.portal.Portal; | ||
import bio.terra.pearl.core.model.portal.PortalEnvironment; | ||
import bio.terra.pearl.core.model.study.PortalStudy; | ||
import bio.terra.pearl.core.model.study.StudyEnvironment; | ||
import bio.terra.pearl.core.service.portal.PortalEnvironmentService; | ||
import bio.terra.pearl.core.service.portal.exception.PortalEnvironmentMissing; | ||
import bio.terra.pearl.core.service.study.StudyEnvironmentService; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
|
||
public class EnforcePortalEnvPermissionAspect extends BaseEnforcePermissionAspect< | ||
PortalEnvAuthContext, EnforcePortalEnvPermission> { | ||
private final AuthUtilService authUtilService; | ||
private final PortalEnvironmentService portalEnvironmentService; | ||
|
||
public EnforcePortalEnvPermissionAspect( | ||
AuthUtilService authUtilService, PortalEnvironmentService portalEnvironmentService) { | ||
this.authUtilService = authUtilService; | ||
this.portalEnvironmentService = portalEnvironmentService; | ||
} | ||
|
||
@Around(value = "@annotation(EnforcePortalEnvPermission)") | ||
public Object enforcePermission(ProceedingJoinPoint joinPoint) throws Throwable { | ||
PortalEnvAuthContext authContext = extractAuthContext(joinPoint); | ||
String permission = getPermissionName(joinPoint); | ||
Portal portal = | ||
authUtilService.authUserToPortalWithPermission( | ||
authContext.getOperator(), authContext.getPortalShortcode(), permission); | ||
authContext.setPortal(portal); | ||
|
||
PortalEnvironment portalEnv = | ||
portalEnvironmentService.findOne( | ||
authContext.getPortalShortcode(), authContext.getEnvironmentName()) | ||
.orElseThrow(PortalEnvironmentMissing::new); | ||
authContext.setPortalEnvironment(portalEnv); | ||
return joinPoint.proceed(); | ||
} | ||
|
||
@Override | ||
protected String getPermissionName(ProceedingJoinPoint joinPoint) { | ||
return ((MethodSignature) joinPoint.getSignature()) | ||
.getMethod() | ||
.getAnnotation(getAnnotationClass()) | ||
.permission(); | ||
} | ||
|
||
@Override | ||
protected Class<PortalEnvAuthContext> getAuthContextClass() { | ||
return PortalEnvAuthContext.class; | ||
} | ||
|
||
@Override | ||
protected Class<EnforcePortalEnvPermission> getAnnotationClass() { | ||
return EnforcePortalEnvPermission.class; | ||
} | ||
public class EnforcePortalEnvPermissionAspect | ||
extends BaseEnforcePermissionAspect<PortalEnvAuthContext, EnforcePortalEnvPermission> { | ||
private final AuthUtilService authUtilService; | ||
private final PortalEnvironmentService portalEnvironmentService; | ||
|
||
public EnforcePortalEnvPermissionAspect( | ||
AuthUtilService authUtilService, PortalEnvironmentService portalEnvironmentService) { | ||
this.authUtilService = authUtilService; | ||
this.portalEnvironmentService = portalEnvironmentService; | ||
} | ||
|
||
@Around(value = "@annotation(EnforcePortalEnvPermission)") | ||
public Object enforcePermission(ProceedingJoinPoint joinPoint) throws Throwable { | ||
PortalEnvAuthContext authContext = extractAuthContext(joinPoint); | ||
String permission = getPermissionName(joinPoint); | ||
Portal portal = | ||
authUtilService.authUserToPortalWithPermission( | ||
authContext.getOperator(), authContext.getPortalShortcode(), permission); | ||
authContext.setPortal(portal); | ||
|
||
PortalEnvironment portalEnv = | ||
portalEnvironmentService | ||
.findOne(authContext.getPortalShortcode(), authContext.getEnvironmentName()) | ||
.orElseThrow(PortalEnvironmentMissing::new); | ||
authContext.setPortalEnvironment(portalEnv); | ||
return joinPoint.proceed(); | ||
} | ||
|
||
@Override | ||
protected String getPermissionName(ProceedingJoinPoint joinPoint) { | ||
return ((MethodSignature) joinPoint.getSignature()) | ||
.getMethod() | ||
.getAnnotation(getAnnotationClass()) | ||
.permission(); | ||
} | ||
|
||
@Override | ||
protected Class<PortalEnvAuthContext> getAuthContextClass() { | ||
return PortalEnvAuthContext.class; | ||
} | ||
|
||
@Override | ||
protected Class<EnforcePortalEnvPermission> getAnnotationClass() { | ||
return EnforcePortalEnvPermission.class; | ||
} | ||
} |
Oops, something went wrong.