use of oap.http.Session in project oap by oaplatform.
the class WsServiceSessionTest method testShouldVerifySessionPropagation.
@Test
public void testShouldVerifySessionPropagation() {
final Session session = new Session();
LinkedHashMap<Integer, Integer> map = Maps.of(__(1, 2));
session.set("map", map);
session.set(Interceptor.AUTHORIZATION, "987654321");
sessionManager.put("123456", session);
assertGet(HttpAsserts.HTTP_URL("/test/"), Maps.empty(), Maps.of(__("Cookie", "Authorization=987654321; SID=123456"))).hasCode(200).hasBody(Binder.json.marshal(map));
}
use of oap.http.Session in project oap by oaplatform.
the class SecurityInterceptor2 method postProcessing.
@Override
public Object postProcessing(Object value, Session session, Reflection.Method method) {
val annotation = method.findAnnotation(WsSecurityWithPermissions.class).orElse(null);
if (annotation == null)
return value;
if (value instanceof List<?>) {
return ((List<?>) value).stream().map(v -> postProcessing(v, session, method)).collect(toList());
}
val userId = (String) session.get(USER_ID).orElse(null);
val id = IdFactory.getId(value);
List<String> res = aclService.checkAll(id, userId);
if (annotation.includeRootPermissions()) {
res = new ArrayList<>(res);
res.addAll(aclService.checkAll(AclService.ROOT, userId));
}
return new ObjectWithPermissions<>(res, value);
}
use of oap.http.Session in project oap by oaplatform.
the class SecurityInterceptor2Test method testShouldNotCheckMethodWithoutAnnotation.
@Test
public void testShouldNotCheckMethodWithoutAnnotation() {
val methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithoutAnnotation")).get();
val httpResponse = securityInterceptor.intercept(new MockRequest(), new Session(), methodWithAnnotation, p -> null);
assertThat(httpResponse).isEmpty();
}
use of oap.http.Session in project oap by oaplatform.
the class SecurityInterceptor2Test method testPostProcessing.
@Test
public void testPostProcessing() {
when(mockAclService.checkAll("1", "testUser")).thenReturn(asList("test1.read"));
final Session session = new Session();
session.set(USER_ID, "testUser");
val methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithAnnotation")).get();
val op = (ObjectWithPermissions) securityInterceptor.postProcessing(new TestAPI.Res("1"), session, methodWithAnnotation);
assertThat(op.permissions).containsExactlyInAnyOrder("test1.read");
}
Aggregations