/** * Inject user identity into operation context. * * @param service the service invoking the operation * @param op operation for which the auth context needs to be set * @param userServicePath user document link * @throws GeneralSecurityException any generic security exception */ public static void assumeIdentity(StatefulService service, Operation op, String userServicePath) throws GeneralSecurityException { Claims.Builder builder = new Claims.Builder(); builder.setSubject(userServicePath); Claims claims = builder.getResult(); String token = service.getTokenSigner().sign(claims); // Setting the AuthContext to null, so that xenon uses the token instead. service.setAuthorizationContext(op, null); op.addRequestHeader(Operation.REQUEST_AUTH_TOKEN_HEADER, token); } }
/** * Inject user identity into operation context. * * @param service * the service invoking the operation * @param op * operation for which the auth context needs to be set * @param userServicePath * user document link * @throws GeneralSecurityException * any generic security exception */ public static void assumeIdentity(StatefulService service, Operation op, String userServicePath) throws GeneralSecurityException { Claims.Builder builder = new Claims.Builder(); builder.setSubject(userServicePath); Claims claims = builder.getResult(); String token = service.getTokenSigner().sign(claims); // Setting the AuthContext to null, so that xenon uses the token instead. service.setAuthorizationContext(op, null); op.addRequestHeader(Operation.REQUEST_AUTH_TOKEN_HEADER, token); }