Germany 's highest court has ruled that random data profiling for terror suspects is legal only when the country faces a specific threat to security or lives .