use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class TenantBasedPermissionEvaluator method hasPermission.
@Override
public boolean hasPermission(Authentication authentication, Object target, Object permission) {
if (target instanceof Optional) {
target = ((Optional<?>) target).orElse(null);
}
if (target == null) {
return false;
}
if (authentication == null) {
return false;
}
CloudbreakUser user = authenticationService.getCloudbreakUser(authentication);
Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target);
return targets.stream().allMatch(t -> hasPermission(user, t));
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class StackImageFilterServiceTest method setupLoggedInUser.
private CloudbreakUser setupLoggedInUser() {
CloudbreakUser user = new CloudbreakUser("", "", "", "", "");
when(authenticatedUserService.getCbUser()).thenReturn(user);
return user;
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class AuditFilterTest method testDoFilterInternalWhenNotAnAuditUrl.
@Test
public void testDoFilterInternalWhenNotAnAuditUrl() throws Exception {
when(authenticatedUserService.getCbUser(any(HttpServletRequest.class))).thenReturn(new CloudbreakUser("userid", "usercrn", "username", "useremail", "usertenant"));
when(request.getRequestURI()).thenReturn("/as/api/healthcheck");
underTest.doFilterInternal(request, response, filterChain);
verifyNoInteractions(auditService);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class TenantBasedPermissionEvaluator method hasPermission.
@Override
public boolean hasPermission(Authentication authentication, Object target, Object permission) {
if (!authentication.isAuthenticated()) {
return true;
}
if (target instanceof Optional) {
target = ((Optional<?>) target).orElse(null);
}
if (target == null) {
return false;
}
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target);
return targets.stream().allMatch(t -> {
if (!(t instanceof Clustered)) {
return true;
}
Cluster cluster = ((Clustered) t).getCluster();
if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) {
return false;
}
cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString());
return true;
});
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class AuditFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
filterChain.doFilter(request, response);
CloudbreakUser cloudbreakUser = authenticatedUserService.getCbUser(request);
if (auditEnabled && includePathPattern(request.getRequestURI())) {
Map<String, Object> requestParameters = new HashMap<>();
requestParameters.put("uri", request.getRequestURI());
requestParameters.putAll(request.getParameterMap());
boolean mutating = Set.of("POST", "PUT", "DELETE").contains(request.getMethod());
String sourceip = Optional.ofNullable(request.getHeader("x-real-ip")).orElse(request.getRemoteAddr());
String userAgent = Optional.ofNullable(request.getHeader("user-agent")).orElse("");
auditService.auditRestApi(requestParameters, mutating, userAgent, cloudbreakUser.getUserCrn(), cloudbreakUser.getTenant(), sourceip);
}
}
Aggregations